MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py
allows using MuJoCo from Python 3.
Upgrade note: Since version 1.50.1.0, only Python 3 is supported. Python 2 users can stay on the 0.5
branch. The latest release there is 0.5.7
which can be installed with pip install mujoco-py==0.5.7
.
- Obtain a 30-day free trial on the MuJoCo website or free license if you are a student. The license key will arrive in an email with your username and password.
- Download the MuJoCo version 1.50 binaries for Linux, OSX, or Windows.
- Unzip the downloaded
mjpro150
directory into~/.mujoco/mjpro150
, and place your license key (themjkey.txt
file from your email) at~/.mujoco/mjkey.txt
.
To include mujoco-py
in another package, add it to your requirements like so:
mujoco-py<1.50.2,>=1.50.1
To play with it interactively, follow these steps:
$ pip install -U 'mujoco-py<1.50.2,>=1.50.1'
$ python
import mujoco_py
from os.path import dirname
model = mujoco_py.load_model_from_path(dirname(dirname(mujoco_py.__file__)) +"/xmls/claw.xml")
sim = mujoco_py.MjSim(model)
print(sim.data.qpos)
# [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
sim.step()
print(sim.data.qpos)
# [ 2.09217903e-06 -1.82329050e-12 -1.16711384e-07 -4.69613872e-11
# -1.43931860e-05 4.73350204e-10 -3.23749942e-05 -1.19854057e-13
# -2.39251380e-08 -4.46750545e-07 1.78771599e-09 -1.04232280e-08]
See the full documentation for advanced usage.
A number of examples demonstrating some advanced features of mujoco-py
can be found in examples/
. These include:
body_interaction.py
: shows interactions between colliding bodiesdisco_fetch.py
: shows howTextureModder
can be used to randomize object texturesinternal_functions.py
: shows how to call raw mujoco functions likemjv_room2model
markers_demo.py
: shows how to add visualization-only geoms to the viewerserialize_model.py
: shows how to save and restore a modelsetting_state.py
: shows how to reset the simulation to a given statesimpool.py
: shows howMjSimPool
can be used to run a number of simulations in paralleltosser.py
: shows a simple actuated object sorting robot application
See the full documentation for advanced usage.
To run the provided unit and integrations tests:
make test
mujoco-py
is maintained by the OpenAI Robotics team. Contributors include:
- Alex Ray
- Bob McGrew
- Jonas Schneider
- Jonathan Ho
- Peter Welinder
- Wojciech Zaremba