Guide to Install OpenAI’s MuJoCo on Ubuntu (Linux)
Follow these simple steps to install OpenAI’s MuJoCo gym environments on Ubuntu (linux):
Step 1. Download MuJoCo
- Download the MuJoCo version 2.1 binaries for Linux or OSX.
- Extract the downloaded
mujoco210
directory into~/.mujoco/mujoco210
.[email protected]:~$ mkdir ~/.mujoco [email protected]:~$ cd PATH_TO_EXTRACTED_FOLDER [email protected]:~$ mv mujoco210 ~/.mujoco/mujoco210
Step 2. Install using pip (python3)
[email protected]:~$ pip3 install -U 'mujoco-py<2.2,>=2.1
Step 3. Export MuJoCo path variable
Add mujoco210 path to your bashrc (or zshrc) file by appeding the following line to your bashrc/zshrc file:
[email protected]:~$ gedit ~/.bashrc
Copy the following line at the end of the file
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/nitishgupta/.mujoco/mujoco210/bin
Step 4. Verify Installation
Finally, verify the installation by executing the following script -
import mujoco_py
# running build_ext
import os
mj_path = mujoco_py.utils.discover_mujoco()
xml_path = os.path.join(mj_path, 'model', 'humanoid.xml')
model = mujoco_py.load_model_from_path(xml_path)
sim = mujoco_py.MjSim(model)
print(sim.data.qpos)
# [0. 0. 1.4 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
# 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
sim.step()
print(sim.data.qpos)
# [-1.12164337e-05 7.29847036e-22 1.39975300e+00 9.99999999e-01
# 1.80085466e-21 4.45933954e-05 -2.70143345e-20 1.30126513e-19
# -4.63561234e-05 -1.88020744e-20 -2.24492958e-06 4.79357124e-05
# -6.38208396e-04 -1.61130312e-03 -1.37554006e-03 5.54173825e-05
# -2.24492958e-06 4.79357124e-05 -6.38208396e-04 -1.61130312e-03
# -1.37554006e-03 -5.54173825e-05 -5.73572648e-05 7.63833991e-05
# -2.12765194e-05 5.73572648e-05 -7.63833991e-05 -2.12765194e-05]
Troubleshooting commonly encountered errors:
fatal error: GL/osmesa.h: No such file or directory
install the following library and try importing mujoco again:
[email protected]:~$ sudo apt-get install libosmesa6-dev
FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'
install the following library and try importing mujoco again:
[email protected]:~$ sudo apt-get install patchelf
That’s it! You should now have MuJoCo installed successfully! Let me know if you face any other difficulties in the comment section below.
Comments