Skip to content

Instantly share code, notes, and snippets.

@saratrajput
Created January 27, 2022 08:26
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save saratrajput/60b1310fe9d9df664f9983b38b50d5da to your computer and use it in GitHub Desktop.
Save saratrajput/60b1310fe9d9df664f9983b38b50d5da to your computer and use it in GitHub Desktop.
Mujoco and Mujoco-py Installation Instructions

Mujoco and Mujoco-py Installation Instructions

The steps are taken from this video and document with some small changes.

Steps

  1. Install Anaconda. Download it from this link.
cd Downloads/
sudo chmod +x Anaconda3-2021.11-Linux-x86_64.sh
./Anaconda3-2021.11-Linux-x86_64.sh
  1. Install git.
sudo apt install git
  1. Install the Mujoco library.

    • Download the Mujoco library from this link.
    • Create a hidden folder :
    mkdir /home/username/.mujoco
    
    • Extract the library to the .mujoco folder.
    tar -xvf mujoco210-linux-x86_64.tar.gz -C ~/.mujoco/
    
    • Include these lines in .bashrc file.
    # Replace user-name with your username
    echo -e 'export LD_LIBRARY_PATH=/home/user-name/.mujoco/mujoco210/bin 
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia 
    export PATH="$LD_LIBRARY_PATH:$PATH" 
    export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so' >> ~/.bashrc
    
    • Source bashrc.
    source ~/.bashrc
    
    • Test that the library is installed.
    cd ~/.mujoco/mujoco210/bin
    ./simulate ../model/humanoid.xml
    
  2. Install mujoco-py.

conda create --name mujoco_py python=3.8
conda activate mujoco_py
sudo apt update
sudo apt-get install patchelf
sudo apt-get install python3-dev build-essential libssl-dev libffi-dev libxml2-dev  
sudo apt-get install libxslt1-dev zlib1g-dev libglew1.5 libglew-dev python3-pip

# Clone mujoco-py.
cd ~/.mujoco
git clone https://github.com/openai/mujoco-py
cd mujoco-py
pip install -r requirements.txt
pip install -r requirements.dev.txt
pip3 install -e . --no-cache
  1. Reboot your machine.
sudo reboot
  1. After reboot, run these commands to install additional packages.
conda activate mujoco_py
sudo apt install libosmesa6-dev libgl1-mesa-glx libglfw3
sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so
# If you get an error like: "ln: failed to create symbolic link '/usr/lib/x86_64-linux-gnu/libGL.so': File exists", it's okay to proceed
pip3 install -U 'mujoco-py<2.2,>=2.1'
  1. Check if mujoco-py is properly installed.
cd ~/.mujoco/mujoco-py/examples
python3 setting_state.py
@Enigma-cit
Copy link

Hi sarat,
I am stuck with the installation of Mujoco in windows 10 for last 2-3 days, it just doesn't find the mujoco-py and showing some errors related to cython and it's kind of urgent for some analysis.
Specs: MUJOCO 2.0.0; Mujoco-py: default from Git-dir
Can you please help me out with this!

@sxzhuang
Copy link

Hi sarat, I am stuck with the installation of Mujoco in windows 10 for last 2-3 days, it just doesn't find the mujoco-py and showing some errors related to cython and it's kind of urgent for some analysis. Specs: MUJOCO 2.0.0; Mujoco-py: default from Git-dir Can you please help me out with this!

Windows 10/11 only supports mjpro150 and mujoco-py 1.50.1.0

@Enigma-cit
Copy link

Okay thanks so much for the info @sxzhuang

@Enigma-cit
Copy link

@sxzhuang can you please provide the installation steps in Windows 10?

thanks very much!

@Charles-Lim93
Copy link

Charles-Lim93 commented Nov 28, 2023

Hi there, When I run

$ sudo apt-get install libxslt1-dev zlib1g-dev libglew1.5 libglew-dev python3-pip

I get following error:

E: Unable to locate package libglew1.5
E: Couldn't find any package by glob 'libglew1.5'
E: Couldn't find any package by regex 'libglew1.5'

Is there any solution or advise i can get? I'm running in Ubuntu 22.04

And does installation (conda create) path for when run conda create --name mujoco_py python=3.8 does matter?

Thank you advance.

@Charles-Lim93
Copy link

It is solved, with changing version [libglew1.5] to [libglew2.2]

Thank you!

@davidireland3
Copy link

I am following this but when I run the test at the end I get the following error:

Compiling /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx
performance hint: /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx:67:5: Exception check on 'c_warning_callback' will always require the GIL to be acquired.
Possible solutions:
	1. Declare 'c_warning_callback' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
	2. Use an 'int' return type on 'c_warning_callback' to allow an error code to be returned.
performance hint: /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx:104:5: Exception check on 'c_error_callback' will always require the GIL to be acquired.
Possible solutions:
	1. Declare 'c_error_callback' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
	2. Use an 'int' return type on 'c_error_callback' to allow an error code to be returned.

Error compiling Cython file:
------------------------------------------------------------
...
    See c_warning_callback, which is the C wrapper to the user defined function
    '''
    global py_warning_callback
    global mju_user_warning
    py_warning_callback = warn
    mju_user_warning = c_warning_callback
                       ^
------------------------------------------------------------

does anyone know what this means/how to fix it?

@Caston1984
Copy link

When i run the last command, I am getting the following error:

File "/home/caston/.mujoco/mujoco-py/examples/setting_state.py", line 7, in
from mujoco_py import load_model_from_xml, MjSim, MjViewer
ImportError: cannot import name 'load_model_from_xml' from 'mujoco_py' (unknown location)

Please assist. Am I missing a library path or what?

@colin-zgf
Copy link

I am following this but when I run the test at the end I get the following error:

Compiling /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx
performance hint: /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx:67:5: Exception check on 'c_warning_callback' will always require the GIL to be acquired.
Possible solutions:
	1. Declare 'c_warning_callback' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
	2. Use an 'int' return type on 'c_warning_callback' to allow an error code to be returned.
performance hint: /home/USER/.mujoco/mujoco-py/mujoco_py/cymj.pyx:104:5: Exception check on 'c_error_callback' will always require the GIL to be acquired.
Possible solutions:
	1. Declare 'c_error_callback' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
	2. Use an 'int' return type on 'c_error_callback' to allow an error code to be returned.

Error compiling Cython file:
------------------------------------------------------------
...
    See c_warning_callback, which is the C wrapper to the user defined function
    '''
    global py_warning_callback
    global mju_user_warning
    py_warning_callback = warn
    mju_user_warning = c_warning_callback
                       ^
------------------------------------------------------------

does anyone know what this means/how to fix it?

pip install "cython<3"

@neurosynapse
Copy link

$ python3 setting_state.py
Compiling /home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/cymj.pyx
/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/cymj.c:797:10: fatal error: mjmodel.h: No such file or directory
797 | #include "mjmodel.h"
| ^~~~~~~~~~~
compilation terminated.
Traceback (most recent call last):
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/unixccompiler.py", line 185, in _compile
self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/ccompiler.py", line 1041, in spawn
spawn(cmd, dry_run=self.dry_run, **kwargs)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/spawn.py", line 70, in spawn
raise DistutilsExecError(
distutils.errors.DistutilsExecError: command '/usr/bin/gcc' failed with exit code 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "setting_state.py", line 7, in
from mujoco_py import load_model_from_xml, MjSim, MjViewer
File "/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/init.py", line 2, in
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/builder.py", line 505, in
cymj = load_cython_ext(mujoco_path)
File "/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/builder.py", line 110, in load_cython_ext
cext_so_path = builder.build()
File "/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/builder.py", line 226, in build
built_so_file_path = self._build_impl()
File "/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/builder.py", line 296, in _build_impl
so_file_path = super()._build_impl()
File "/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/builder.py", line 249, in _build_impl
dist.run_commands()
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
self.run_command(cmd)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/dist.py", line 989, in run_command
super().run_command(command)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
_build_ext.build_ext.run(self)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run
self.build_extensions()
File "/home/rob/git_repos/reinforcement_learning/mujoco-py/mujoco_py/builder.py", line 149, in build_extensions
build_ext.build_extensions(self)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
_build_ext.build_ext.build_extensions(self)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 467, in build_extensions
self._build_extensions_serial()
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 493, in _build_extensions_serial
self.build_extension(ext)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 548, in build_extension
objects = self.compiler.compile(
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/ccompiler.py", line 600, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/home/rob/anaconda3/envs/mujoco_py/lib/python3.8/site-packages/setuptools/_distutils/unixccompiler.py", line 187, in _compile
raise CompileError(msg)
distutils.errors.CompileError: command '/usr/bin/gcc' failed with exit code 1

@Maisa-ASM
Copy link

same error as @neurosynapse , any solution?

@aeroSapphire
Copy link

When i run,
python3 setting_state.py
I get the following error:
`Creating window glfw
ERROR: GLEW initalization error: Unknown error

Press Enter to exit ...`
Any help regarding this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment