Skip to content

Instantly share code, notes, and snippets.

@johannah
Last active April 5, 2022 17:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johannah/9266e8d5c7698e53af5f193057e3cfd7 to your computer and use it in GitHub Desktop.
Save johannah/9266e8d5c7698e53af5f193057e3cfd7 to your computer and use it in GitHub Desktop.
# to get mujoco-py to install with headless rendering without sudo access
##############################
# 1) first download and install mujoco according to instructions from https://github.com/deepmind/mujoco/
##############################
# 2) add environment variables to your bashrc
# importantly, this should be done before installing mujoco-py
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/$USER/.mujoco/mujoco210/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia
# egl allows for headless rendering on linux
export MUJOCO_GL="egl"
##############################
# 3) Create and activate conda environment. For this doc, I've named it "mujoco_env"
conda create -n mujoco_env python=3.9
# install several rendering requirements to get around apt-get install requirements
conda install -c conda-forge glew
conda install -c conda-forge patchelf
conda install -c menpo glfw3
##############################
# 4) clone and install mujoco-py from source
git clone https://github.com/openai/mujoco-py
cd mujoco-py
python setup.py install
##############################
# 5) Mujoco-py will compile the first time it is imported after being installed.
# You need to ensure when this compilation happens, mujoco-py will have access to
# the rendering libraries we've installed with conda. The most reliable way I've found
# to do this is to ensure this process occurs within your conda environments include directory.
# You should also be able to add this include path to your environment path so that mujoco-py
# can find it during compilation, but I haven't managed to get that to work yet.
cd ~/anaconda3/envs/mujoco_env/include
python
>> import mujoco_py
# mujoco will compile for several minutes
# now type "mujoco_py.cymj" and ensure "linuxgpuextensionbuilder" is included in the printout. Mine is: <module 'cymj' from
# '/home/user/anaconda3/envs/mujoco_env/lib/python3.8/site-packages/mujoco_py-2.1.2.14-py3.8.egg/mujoco_py/generated/cymj_2.1.2.14_38_linuxgpuextensionbuilder_38.so'>
>> mujoco_py.cymj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment