mujoco-py icon indicating copy to clipboard operation
mujoco-py copied to clipboard

Support MuJoCo 2.1.1 (including arm64 mac support)

Open wookayin opened this issue 3 years ago • 36 comments

I hope this can be a tracking issue for supporting MuJoCo 2.1.1, which was just released few hours ago. There are some incompatible changes, so the python binding mujoco-py also needs to catch up those changes.

Required changes include:

  • The path to the shared library has changed to lib/libmujoco.so (previously bin/libmujoco210.so)
  • Perhaps expected installation paths might be $HOME/.mujoco/mujoco211 per the convention. However, this naming convention is because of the directory name in the archive, which is mujoco210; the new release 2.1.1 no longer uses this convention. Therefore mujoco installation path might also need to be changed (discussion/opinion needed).
  • For MacOS, MuJoCo is now provided as a Framework bundle, so it is no longer expected to have a load path under $HOME/.mujoco. The standard MuJoCo installation path on MacOS systems seems undetermined yet, so we might need to wait a bit more to hear from DeepMind.

In addition, the builder script also needs to be updated because currently GCC only up to v9 is supported: https://github.com/openai/mujoco-py/issues/605.

I already managed to make mujoco-py work locally on my M1 machines, so creating and submitting a patch will be quite straightforward but we'll have to make a few decisions.

wookayin avatar Dec 16 '21 18:12 wookayin

Last update: 2022/05/24 (for Mujoco 2.2.x release), see this comment

Workaround: mujoco-py installation for Mujoco 2.1.1

Until mujoco-py gets updated to officially support DeepMind's MuJoCo 2.1+, you can try the following as a hacky workaround.

First, make sure your python is running as arm64 (NOT x86_64 under Rosetta 2). For instance, you can use miniforge3.

$ which python3
/Users/$ID/.miniforge3/bin/python3
$ lipo -archs $(which python3)
arm64

Now run the following:

mkdir -p $HOME/.mujoco/mujoco210         # Remove existing installation if any
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/Headers/ $HOME/.mujoco/mujoco210/include
mkdir -p $HOME/.mujoco/mujoco210/bin
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.*.dylib $HOME/.mujoco/mujoco210/bin/libmujoco210.dylib
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.*.dylib /usr/local/lib/

# For M1 (arm64) mac users:
# The released binary doesn't ship glfw3, so need to install on your own
brew install glfw
ln -sf /opt/homebrew/lib/libglfw.3.dylib $HOME/.mujoco/mujoco210/bin

# Please make sure /opt/homebrew/bin/gcc-11  exists: install gcc if you haven't already
# brew install gcc
export CC=/opt/homebrew/bin/gcc-11         # see https://github.com/openai/mujoco-py/issues/605

pip install mujoco-py && python -c 'import mujoco_py'

Note / Troubleshoothing:

  • I assumed that you copied MuJoCo.app into /Applications (this is the recommended installation). Or you can feel free to change the path as you'd like, for example, /Volume/MuJoCo/MuJoCo.app if you simply mounted the dmg file from the downloaded archive file.

  • If you see mujoco-py complaining about GCC@9, you probably have missed export CC=/opt/homebrew/bin/gcc-11

  • When upgrading MuJoCo installation (e.g., from 2.1.1 to 2.2.0), be sure to remove the existing extension (or reinstall mujoco-py) so that mujoco-py can rebuild the extension. For example:

    rm -rf $HOME/.miniforge3/lib/python3.9/site-packages/mujoco_py/generated/*extensionbuilder*
    
  • Excuse the (wrong) directory name mujoco210 and library name libmujoco210.dylib because mujoco-py==2.1.* expects the mujoco installation directory/library name as if they were mujoco 2.1.0. This is, again, just a temporary workaround.

Done!

After this step, you should be able to run MuJoCo on a Apple Silicon Mac!

image

wookayin avatar Dec 16 '21 18:12 wookayin

Thanks for the tutorial!

My brew packages installed to different paths than the ones above, so I had to make the following adjustments:

# glfw
ln -sf /usr/local/Cellar/glfw/3.3.6/lib/libglfw.3.3.dylib $HOME/.mujoco/mujoco210/bin

# gcc
export CC=/usr/local/Cellar/gcc/11.2.0_3/bin/gcc-11

edwhu avatar Dec 17 '21 02:12 edwhu

Screen Shot 2021-12-16 at 6 26 55 PM

I got this error, even though everything compiled smoothly. I suspect this is because I am using the x86_64 emulation mode on m1. I'll try again in arm64 mode.

edwhu avatar Dec 17 '21 02:12 edwhu

If you are using an Intel mac, glfw installation path would be different. Please feel free to change the path accordingly. BTW, it is very recommended to have the brew command dedicated for arm64 architectures (i.e., manages packages in /opt/homebrew/Cellar/...), not for x86_64 (/usr/local/Cellar/..), although you may have alternative homebrew installation for x86_64 (/usr/local/bin/brew).

The x86_64 binary requires AVX instruction, which is not supported on M1 machines. The only way is to use arm64 python: ~I recommend using miniforge3 (arm64) rather than miniconda3 (no arm64 support yet)~.

UPDATE: miniconda3 has arm64 support since 2021-11-08.

wookayin avatar Dec 17 '21 02:12 wookayin

Thanks for the tip! I got it running. There were some things I had to undo to get it working.

  1. In general, my M1 terminal and brew was set to x86_64 emulation mode, so I had to undo that (e.g. turn off Rosetta emulation for iTerm.app, install brew for arm64).
  2. Uninstall glfw / gcc for the x86_64 brew, and reinstall glfw/gcc using the arm64 brew.
  3. My miniconda env was built for intel. Miniconda actually supports Arm now, so I installed that version.

After doing these changes, my paths exactly matched the original post's paths. Then everything works.

edwhu avatar Dec 17 '21 03:12 edwhu

`RuntimeError: Could not find supported GCC executable.

HINT: On OS X, install GCC 9.x with brew install gcc@9. or port install gcc9`

I'm getting this error when I try to run pip install mujoco-py && python -c 'import mujoco_py' but I already have gcc 11.2.0_3 installed. I'm not sure why I'm getting this error

raviswaroop-98 avatar Dec 17 '21 03:12 raviswaroop-98

Did you make sure the CC variable was set, i.e. export CC=/opt/homebrew/bin/gcc-11

edwhu avatar Dec 17 '21 03:12 edwhu

Yeah my bad made a spelling mistake. But now I have a different error when I try to import MuJoCo_py

Import error. Trying to rebuild mujoco_py. running build_ext Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/raviswarooprayavarapu/opt/anaconda3/lib/python3.9/site-packages/mujoco_py/__init__.py", line 2, in <module> from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException File "/Users/raviswarooprayavarapu/opt/anaconda3/lib/python3.9/site-packages/mujoco_py/builder.py", line 504, in <module> cymj = load_cython_ext(mujoco_path) File "/Users/raviswarooprayavarapu/opt/anaconda3/lib/python3.9/site-packages/mujoco_py/builder.py", line 111, in load_cython_ext mod = load_dynamic_ext('cymj', cext_so_path) File "/Users/raviswarooprayavarapu/opt/anaconda3/lib/python3.9/site-packages/mujoco_py/builder.py", line 130, in load_dynamic_ext return loader.load_module() ImportError: dlopen(/Users/raviswarooprayavarapu/opt/anaconda3/lib/python3.9/site-packages/mujoco_py/generated/cymj_2.1.2.14_39_macextensionbuilder_39.so, 0x0002): tried: '/Users/raviswarooprayavarapu/opt/anaconda3/lib/python3.9/site-packages/mujoco_py/generated/cymj_2.1.2.14_39_macextensionbuilder_39.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/cymj_2.1.2.14_39_macextensionbuilder_39.so' (no such file), '/usr/lib/cymj_2.1.2.14_39_macextensionbuilder_39.so' (no such file)

I'm using x86 anaconda on rosseta, that might be the issue I'll try uninstalling that and try installing conda-forge native version.

raviswaroop-98 avatar Dec 17 '21 04:12 raviswaroop-98

anaconda is not native for m1 and its trying to compile mujoco_py for x86. Uninstalling anaconda and installing miniforge3 which is native for m1 solved the error.

raviswaroop-98 avatar Dec 17 '21 05:12 raviswaroop-98

Thanks for the tutorial!!

XuJing1022 avatar Jan 07 '22 03:01 XuJing1022

Until mujoco-py gets updated to officially support MuJoCo 2.1.1, the following should work as a hacky workaround.

First, make sure your python is running arm64 (NOT x86_64 under Rosetta 2).

mkdir -p $HOME/.mujoco/mujoco210         # Remove existing installation if any
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/Headers/ $HOME/.mujoco/mujoco210/include
mkdir -p $HOME/.mujoco/mujoco210/bin
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.1.1.dylib $HOME/.mujoco/mujoco210/bin/libmujoco210.dylib
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.1.1.dylib /usr/local/lib/

# For M1 (arm64) mac users:
# The released binary doesn't ship glfw3, so need to install on your own
brew install glfw
ln -sf /opt/homebrew/lib/libglfw.3.dylib $HOME/.mujoco/mujoco210/bin
export CC=/opt/homebrew/bin/gcc-11         # see https://github.com/openai/mujoco-py/issues/605

pip install mujoco-py && python -c 'import mujoco_py'

I assumed that you copied MuJoCo.app into /Applications. Or you can feel free to change the path as you'd like, for example, /Volume/MuJoCo/MuJoCo.app if you simply mounted the dmg file from the downloaded archive file.

Excuse the (wrong) directory name mujoco210 and library name libmujoco210.dylib because mujoco-py==2.1.* expects the mujoco installation directory/library name as if they were mujoco 2.1.0. This is, again, just a temporary workaround.

After this step, you should be able to run MuJoCo on a Apple Silicon Mac!

image

Even after following these steps, I am getting the following error:

Import error. Trying to rebuild mujoco_py.
running build_ext
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mujoco_py/__init__.py", line 2, in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mujoco_py/builder.py", line 504, in <module>
    cymj = load_cython_ext(mujoco_path)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mujoco_py/builder.py", line 111, in load_cython_ext
    mod = load_dynamic_ext('cymj', cext_so_path)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mujoco_py/builder.py", line 130, in load_dynamic_ext
    return loader.load_module()
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mujoco_py/generated/cymj_2.1.2.14_39_macextensionbuilder_39.so, 2): Library not loaded: @rpath/MuJoCo.framework/Versions/A/libmujoco.2.1.1.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mujoco_py/generated/cymj_2.1.2.14_39_macextensionbuilder_39.so
  Reason: image not found

What might be the issue here?

guptav96 avatar Jan 17 '22 04:01 guptav96

Thanks for the tutorial!

My brew packages installed to different paths than the ones above, so I had to make the following adjustments:

# glfw
ln -sf /usr/local/Cellar/glfw/3.3.6/lib/libglfw.3.3.dylib $HOME/.mujoco/mujoco210/bin

# gcc
export CC=/usr/local/Cellar/gcc/11.2.0_3/bin/gcc-11

Got it to work in intel mac by changing the version in the symbolic link to .3 rather than 3.3, ie.:

ln -sf /usr/local/Cellar/glfw/3.3.6/lib/libglfw.3.dylib $HOME/.mujoco/mujoco210/bin

enajx avatar Jan 18 '22 16:01 enajx

I get the following error on trying to run mujoco_py on mac_osx

Compiling /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/cymj.pyx
running build_ext
building 'mujoco_py.cymj' extension
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py
creating /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/gl
/opt/homebrew/bin/gcc-11 -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -DONMAC -I/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py -I/Users/tanmaykulkarni/.mujoco/mujoco210/include -I/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/numpy/core/include -I/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/cymj.c -o /Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14.6-arm64-3.8/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/cymj.o -fopenmp -w
gcc-11: warning: this compiler does not support X86 (arch flags ignored)
gcc-11: error: unrecognized command-line option '-iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders'
gcc-11: error: unrecognized command-line option '-iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers'
Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/unixccompiler.py", line 118, in _compile
    self.spawn(compiler_so + cc_args + [src, '-o', obj] +
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/spawn.py", line 157, in _spawn_posix
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command '/opt/homebrew/bin/gcc-11' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/__init__.py", line 2, in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/builder.py", line 504, in <module>
    cymj = load_cython_ext(mujoco_path)
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/builder.py", line 110, in load_cython_ext
    cext_so_path = builder.build()
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/builder.py", line 226, in build
    built_so_file_path = self._build_impl()
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/builder.py", line 343, in _build_impl
    so_file_path = super()._build_impl()
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/builder.py", line 249, in _build_impl
    dist.run_commands()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py", line 340, in run
    self.build_extensions()
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/mujoco_py/builder.py", line 149, in build_extensions
    build_ext.build_extensions(self)
  File "/Users/tanmaykulkarni/Courses/Spring/RA/Research/RAPS/raps/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
    _build_ext.build_ext.build_extensions(self)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
    self._build_extensions_serial()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
    self.build_extension(ext)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py", line 528, in build_extension
    objects = self.compiler.compile(sources,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/ccompiler.py", line 574, in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/unixccompiler.py", line 121, in _compile
    raise CompileError(msg)
distutils.errors.CompileError: command '/opt/homebrew/bin/gcc-11' failed with exit status 1```

I followed the instructions given in 

> Until `mujoco-py` gets updated to officially support MuJoCo 2.1.1, the following should work as a _hacky_ workaround.
> 
> First, make sure your python is running **arm64** (NOT x86_64 under Rosetta 2).
> 
> ```shell
> mkdir -p $HOME/.mujoco/mujoco210         # Remove existing installation if any
> ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/Headers/ $HOME/.mujoco/mujoco210/include
> mkdir -p $HOME/.mujoco/mujoco210/bin
> ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.1.1.dylib $HOME/.mujoco/mujoco210/bin/libmujoco210.dylib
> ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.1.1.dylib /usr/local/lib/
> 
> # For M1 (arm64) mac users:
> # The released binary doesn't ship glfw3, so need to install on your own
> brew install glfw
> ln -sf /opt/homebrew/lib/libglfw.3.dylib $HOME/.mujoco/mujoco210/bin
> export CC=/opt/homebrew/bin/gcc-11         # see https://github.com/openai/mujoco-py/issues/605
> 
> pip install mujoco-py && python -c 'import mujoco_py'
> ```
> 
> I assumed that you copied `MuJoCo.app` into `/Applications`. Or you can feel free to change the path as you'd like, for example, `/Volume/MuJoCo/MuJoCo.app` if you simply mounted the `dmg` file from the downloaded archive file.
> 
> Excuse the (wrong) directory name `mujoco210` and library name `libmujoco210.dylib` because `mujoco-py==2.1.*` expects the mujoco installation directory/library name as if they were mujoco 2.1.0. This is, again, just a temporary workaround.
> 
> After this step, you should be able to run MuJoCo on a Apple Silicon Mac!
> 
> ![image](https://user-images.githubusercontent.com/1009873/146427768-fbaf6d45-9325-4001-8b8b-07c5afc01dec.png)

But on running ` python -c 'import mujoco_py'` it is not able to build successfully. I am currently using the arm64 version of python as well as gcc. Can someone help me with this...

Tanmay-Kulkarni101 avatar Jan 26 '22 16:01 Tanmay-Kulkarni101

@wookayin Thank you so much for putting in a workaround for now. In my case, /usr/local/lib did not exist so I had to sudo mkdir /usr/local/lib manually. This didn't seem necessary before but I had another error which required this.

nikhilweee avatar Jan 27 '22 06:01 nikhilweee

killed python -c 'import mujoco_py'

creating /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/lib.macosx-11.0-arm64-3.9
creating /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/lib.macosx-11.0-arm64-3.9/mujoco_py
/opt/homebrew/bin/gcc-11 -bundle -undefined dynamic_lookup -Wl,-rpath,/opt/homebrew/Caskroom/miniforge/base/lib -L/opt/homebrew/Caskroom/miniforge/base/lib -Wl,-rpath,/opt/homebrew/Caskroom/miniforge/base/lib -L/opt/homebrew/Caskroom/miniforge/base/lib -arch arm64 /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.0-arm64-3.9/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/mujoco_py/cymj.o /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.0-arm64-3.9/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/mujoco_py/gl/dummyshim.o -L/Users//.mujoco/mujoco210/bin -L/Users//.mujoco/mujoco210/bin -lmujoco210 -lglfw.3 -o /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/lib.macosx-11.0-arm64-3.9/mujoco_py/cymj.cpython-39-darwin.so -fopenmp
ld: warning: dylib (/Users//.mujoco/mujoco210/bin/libglfw.3.dylib) was built for newer macOS version (12.0) than being linked (11.0)
[1]    88759 killed     python -c 'import mujoco_py'

Does anyone have idea? Thanks.

TachikakaMin avatar Feb 10 '22 22:02 TachikakaMin

I followed the steps indicated by @wookayin and it worked perfectly in my Macbook m1 max machine running Monterey 12.2.1. After a couple of weeks when I updated my mac to the Monterey beta 12.3 version, I begin to get distutils.errors.CompileError: command '/opt/homebrew/bin/gcc-11' failed with exit status 5. After doing everything I could, I had to factory reset my MacBook to a non-beta version (back to 12.2.1) and was able to install it correctly again. Now, I am skeptical to run any update. Not sure if I won't see this update in the next stable version of mac.

bikcrum avatar Feb 13 '22 07:02 bikcrum

Until mujoco-py gets updated to officially support MuJoCo 2.1.1, the following should work as a hacky workaround.

First, make sure your python is running arm64 (NOT x86_64 under Rosetta 2).

mkdir -p $HOME/.mujoco/mujoco210         # Remove existing installation if any
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/Headers/ $HOME/.mujoco/mujoco210/include
mkdir -p $HOME/.mujoco/mujoco210/bin
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.1.1.dylib $HOME/.mujoco/mujoco210/bin/libmujoco210.dylib
ln -sf /Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework/Versions/Current/libmujoco.2.1.1.dylib /usr/local/lib/

# For M1 (arm64) mac users:
# The released binary doesn't ship glfw3, so need to install on your own
brew install glfw
ln -sf /opt/homebrew/lib/libglfw.3.dylib $HOME/.mujoco/mujoco210/bin
export CC=/opt/homebrew/bin/gcc-11         # see https://github.com/openai/mujoco-py/issues/605

pip install mujoco-py && python -c 'import mujoco_py'

I assumed that you copied MuJoCo.app into /Applications. Or you can feel free to change the path as you'd like, for example, /Volume/MuJoCo/MuJoCo.app if you simply mounted the dmg file from the downloaded archive file.

Excuse the (wrong) directory name mujoco210 and library name libmujoco210.dylib because mujoco-py==2.1.* expects the mujoco installation directory/library name as if they were mujoco 2.1.0. This is, again, just a temporary workaround.

After this step, you should be able to run MuJoCo on a Apple Silicon Mac!

image

What if I need to mujoco 1.5 (aka mjpro150) for gym, does the same workaround work?

alexyalunin avatar Feb 16 '22 13:02 alexyalunin

I got distutils.errors.CompileError: command '/opt/homebrew/bin/gcc-11' failed: No such file or directory on my M1 macbookpro.

zdhNarsil avatar Mar 17 '22 01:03 zdhNarsil

I got distutils.errors.CompileError: command '/opt/homebrew/bin/gcc-11' failed: No such file or directory on my M1 macbookpro.

@zdhNarsil I suggest you need to first go to confirm if you have installed the homebrew in your macbook. Once you have installed it, you can use which brew to identify the location of homebrew. Finally, you can use brew install gcc@11 to install gcc-11. I have successfully installed MuJoCo on my machine according to @wookayin 's instruction.

TianhongDai avatar Mar 17 '22 11:03 TianhongDai

I've done all the setups suggested by @wookayin but still getting this error: ld: library not found for -lmujoco210 I've also tried the following possible steps:

❯ export LIBRARY_PATH=$LIBRARY_PATH:/Users/$USER/.mujoco
❯ export LIBRARY_PATH=$LIBRARY_PATH:/Users/$USER/.mujoco/mujoco210/
❯ export LIBRARY_PATH=$LIBRARY_PATH:/Users/$USER/.mujoco/mujoco210/bin
❯ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Users/$USER/.mujoco
❯ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Users/$USER/.mujoco/mujoco210/
❯ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Users/$USER/.mujoco/mujoco210/bin

But none of them works... Do you have nny ideas?

The full error message is:

❯ python -c 'import mujoco_py'
running build_ext
building 'mujoco_py.cymj' extension
/opt/homebrew/bin/gcc-11 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/jexus/miniforge3/include -arch arm64 -fPIC -O2 -isystem /Users/jexus/miniforge3/include -arch arm64 -DONMAC -I/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py -I/Users/jexus/.mujoco/mujoco210/include -I/Users/jexus/miniforge3/lib/python3.9/site-packages/numpy/core/include -I/Users/jexus/miniforge3/include/python3.9 -c /Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/cymj.c -o /Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.0-arm64-3.9/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/cymj.o -fopenmp -w
/opt/homebrew/bin/gcc-11 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/jexus/miniforge3/include -arch arm64 -fPIC -O2 -isystem /Users/jexus/miniforge3/include -arch arm64 -DONMAC -I/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py -I/Users/jexus/.mujoco/mujoco210/include -I/Users/jexus/miniforge3/lib/python3.9/site-packages/numpy/core/include -I/Users/jexus/miniforge3/include/python3.9 -c /Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/gl/dummyshim.c -o /Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.0-arm64-3.9/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/gl/dummyshim.o -fopenmp -w
/opt/homebrew/bin/gcc-11 -bundle -undefined dynamic_lookup -Wl,-rpath,/Users/jexus/miniforge3/lib -L/Users/jexus/miniforge3/lib -Wl,-rpath,/Users/jexus/miniforge3/lib -L/Users/jexus/miniforge3/lib /Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.0-arm64-3.9/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/cymj.o /Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.0-arm64-3.9/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/gl/dummyshim.o -L/Users/jexus/.mujoco/mujoco210/bin -Wl,-rpath,/Users/jexus/.mujoco/mujoco210/bin -lmujoco210 -lglfw.3 -o /Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/lib.macosx-11.0-arm64-3.9/mujoco_py/cymj.cpython-39-darwin.so -fopenmp
ld: library not found for -lmujoco210
collect2: error: ld returned 1 exit status
Traceback (most recent call last):
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py", line 204, in link
    self.spawn(linker + ld_args)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py", line 917, in spawn
    spawn(cmd, dry_run=self.dry_run, **kwargs)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/spawn.py", line 68, in spawn
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command '/opt/homebrew/bin/gcc-11' failed with exit code 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/__init__.py", line 2, in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/builder.py", line 504, in <module>
    cymj = load_cython_ext(mujoco_path)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/builder.py", line 110, in load_cython_ext
    cext_so_path = builder.build()
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/builder.py", line 226, in build
    built_so_file_path = self._build_impl()
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/builder.py", line 343, in _build_impl
    so_file_path = super()._build_impl()
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/builder.py", line 249, in _build_impl
    dist.run_commands()
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
    self.run_command(cmd)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
    cmd_obj.run()
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 339, in run
    self.build_extensions()
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/mujoco_py/builder.py", line 149, in build_extensions
    build_ext.build_extensions(self)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
    _build_ext.build_ext.build_extensions(self)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 448, in build_extensions
    self._build_extensions_serial()
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 473, in _build_extensions_serial
    self.build_extension(ext)
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 550, in build_extension
    self.compiler.link_shared_object(
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py", line 713, in link_shared_object
    self.link(CCompiler.SHARED_OBJECT, objects,
  File "/Users/jexus/miniforge3/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py", line 206, in link
    raise LinkError(msg)
distutils.errors.LinkError: command '/opt/homebrew/bin/gcc-11' failed with exit code 1

voidism avatar Mar 27 '22 18:03 voidism

I was also getting the error distutils.errors.DistutilsExecError: command '/opt/homebrew/bin/gcc-11' failed with exit code 1

I was using Mujoco-2.1.3. Then I deleted it and downloaded mujoco-2.1.1-macos-universal2.dmg. I copied the MuJoCo.app to /Applications and double-clicked it to open the app. I ran the installation script again and it worked.

(I'm using miniforge3, python=3.9.1, macOS Monterey 12.1.)

liusf15 avatar Mar 29 '22 17:03 liusf15

@liusf15 It really works!!!!! Thank a lot!!

Skywuuuu avatar Apr 07 '22 10:04 Skywuuuu

I updated my instruction above to catch up with the recent Mujoco v2.2.0 release. Summary of changes are:

  • Added an instruction to remove previous mujoco-py extensions after upgrading Mujoco to v2.2 (needs recompilation)
  • Updated the command line instructions to correctly handle libmujoco.2.2.0.dylib (due to version/filename change)
  • Added more fool-proof instructions (like CC variables).

UPDATE: It looks like the ABI of Mujoco 2.2.0 is NOT compatible with mujoco-py, resulting in Segmentation fault:

AssertionError: 
Exception ignored in: 'mujoco_py.cymj.PyMjModel._set'
Traceback (most recent call last):
  File "wrappers.pxi", line 1139, in mujoco_py.cymj.PyMjModel._extract_mj_names

Until somebody figure out a workaround, please stick to mujoco 2.1.1 to use the obsolete mujoco-py bindings. The installation instruction will work for both versions.

wookayin avatar May 24 '22 17:05 wookayin

In 2022, gym has migrated to use the official mujoco python bindings from mujoco-py: https://github.com/openai/gym/pull/2762 (which was just merged today).

From README:

MuJoCo Environments

The latest "_v4" and future versions of the MuJoCo environments will no longer depend on mujoco-py. Instead mujoco will be the required dependency for future gym MuJoCo environment versions. Old gym MuJoCo environment versions that depend on mujoco-py will still be kept but unmaintained. To install the dependencies for the latest gym MuJoCo environments use pip install gym[mujoco]. Dependencies for old MuJoCo environments can still be installed by pip install gym[mujoco_py].

If you plan to use MuJoCo 2.2.0, please use gym v0.24.0 (which will be released soon). This workaround is only valid for MuJoCo 2.1.x.

wookayin avatar May 24 '22 17:05 wookayin

I was having trouble installing cffi, and switching miniconda3 to miniforge by brew install miniforge fixed the error below:

Building wheels for collected packages: cffi
  Building wheel for cffi (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/mandizhao/miniconda3/envs/misc/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/0j/r5d7_tp12dg98vxjscspcxv00000gn/T/pip-install-tq1tt2ck/cffi_c4519b1001ea4ac6bc7aaaeaaf4f8dc6/setup.py'"'"'; __file__='"'"'/private/var/folders/0j/r5d7_tp12dg98vxjscspcxv00000gn/T/pip-install-tq1tt2ck/cffi_c4519b1001ea4ac6bc7aaaeaaf4f8dc6/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/0j/r5d7_tp12dg98vxjscspcxv00000gn/T/pip-wheel-35zkwthz
       cwd: /private/var/folders/0j/r5d7_tp12dg98vxjscspcxv00000gn/T/pip-install-tq1tt2ck/cffi_c4519b1001ea4ac6bc7aaaeaaf4f8dc6/
  Complete output (33 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-11.1-arm64-3.8
  creating build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/backend_ctypes.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/error.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/setuptools_ext.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/__init__.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/cffi_opcode.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/vengine_gen.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/pkgconfig.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/model.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/ffiplatform.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/api.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/vengine_cpy.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/commontypes.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/lock.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/recompiler.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/cparser.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/verifier.py -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/_cffi_include.h -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/parse_c_type.h -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/_embedding.h -> build/lib.macosx-11.1-arm64-3.8/cffi
  copying cffi/_cffi_errors.h -> build/lib.macosx-11.1-arm64-3.8/cffi
  running build_ext
  building '_cffi_backend' extension
  creating build/temp.macosx-11.1-arm64-3.8
  creating build/temp.macosx-11.1-arm64-3.8/c
  /opt/homebrew/bin/gcc-11 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/mandizhao/miniconda3/envs/misc/include -arch arm64 -I/Users/mandizhao/miniconda3/envs/misc/include -arch arm64 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/Users/mandizhao/miniconda3/envs/misc/include/python3.8 -c c/_cffi_backend.c -o build/temp.macosx-11.1-arm64-3.8/c/_cffi_backend.o -iwithsysroot/usr/include/ffi
  gcc-11: error: unrecognized command-line option '-iwithsysroot/usr/include/ffi'
  error: command '/opt/homebrew/bin/gcc-11' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for cffi
  Running setup.py clean for cffi
Failed to build cffi

MandiZhao avatar Jun 01 '22 15:06 MandiZhao

I was having trouble installing process when test with the following code, python3 import mujoco_py 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) and get the error: model = mujoco_py.load_model_from_path(xml_path) Traceback (most recent call last): File "", line 1, in File "cymj.pyx", line 175, in mujoco_py.cymj.load_model_from_path Exception: Failed to load XML file: /Users/jack/.mujoco/mujoco210/model/humanoid.xml. mj_loadXML error: b'XML parse error 3:\nError=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=/Users/jack/.mujoco/mujoco210/model/humanoid.xml\n'

zhuyuanyang avatar Jul 07 '22 13:07 zhuyuanyang

I updated my instruction above to catch up with the recent Mujoco v2.2.0 release. Summary of changes are:

  • Added an instruction to remove previous mujoco-py extensions after upgrading Mujoco to v2.2 (needs recompilation)
  • Updated the command line instructions to correctly handle libmujoco.2.2.0.dylib (due to version/filename change)
  • Added more fool-proof instructions (like CC variables).

UPDATE: It looks like the ABI of Mujoco 2.2.0 is NOT compatible with mujoco-py, resulting in Segmentation fault:

AssertionError: 
Exception ignored in: 'mujoco_py.cymj.PyMjModel._set'
Traceback (most recent call last):
  File "wrappers.pxi", line 1139, in mujoco_py.cymj.PyMjModel._extract_mj_names

Until somebody figure out a workaround, please stick to mujoco 2.1.1 to use the obsolete mujoco-py bindings. The installation instruction will work for both versions.

I guess only 2.1.1 works. Failed to install for 2.2.0 due to gcc compiler error.

jaku-jaku avatar Jul 07 '22 19:07 jaku-jaku

I try it again, and find the issue which may be resulting in the above errors. When i install and execute the "pip install mujoco-py && python -c 'import mujoco_py'", i obtain the following errors: The operation is based on Macos 12.4 and Apple clang version 13.1.6 (clang-1316.0.21.2.5). Collecting mujoco-py Downloading mujoco_py-2.1.2.14-py3-none-any.whl (2.4 MB) |████████████████████████████████| 2.4 MB 1.0 MB/s Requirement already satisfied: glfw>=1.4.0 in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from mujoco-py) (2.5.3) Requirement already satisfied: imageio>=2.1.2 in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from mujoco-py) (2.19.3) Requirement already satisfied: fasteners~=0.15 in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from mujoco-py) (0.17.3) Requirement already satisfied: cffi>=1.10 in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from mujoco-py) (1.15.0) Requirement already satisfied: numpy>=1.11 in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from mujoco-py) (1.22.3) Requirement already satisfied: Cython>=0.27.2 in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from mujoco-py) (0.29.30) Requirement already satisfied: pycparser in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from cffi>=1.10->mujoco-py) (2.21) Requirement already satisfied: pillow>=8.3.2 in ./opt/anaconda3/envs/RL/lib/python3.9/site-packages (from imageio>=2.1.2->mujoco-py) (9.0.1) Installing collected packages: mujoco-py Successfully installed mujoco-py-2.1.2.14 Compiling /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/cymj.pyx because it changed. [1/1] Cythonizing /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/cymj.pyx running build_ext building 'mujoco_py.cymj' extension creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9 creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3 creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9 creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/gl /opt/homebrew/bin/gcc-11 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/jack/opt/anaconda3/envs/RL/include -arch arm64 -I/Users/jack/opt/anaconda3/envs/RL/include -fPIC -O2 -isystem /Users/jack/opt/anaconda3/envs/RL/include -arch arm64 -DONMAC -Iopt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py -I/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py -I/Users/jack/.mujoco/mujoco210/include -I/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/numpy/core/include -I/Users/jack/opt/anaconda3/envs/RL/include/python3.9 -c /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/cymj.c -o /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/cymj.o -fopenmp -w /opt/homebrew/bin/gcc-11 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/jack/opt/anaconda3/envs/RL/include -arch arm64 -I/Users/jack/opt/anaconda3/envs/RL/include -fPIC -O2 -isystem /Users/jack/opt/anaconda3/envs/RL/include -arch arm64 -DONMAC -Iopt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py -I/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py -I/Users/jack/.mujoco/mujoco210/include -I/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/numpy/core/include -I/Users/jack/opt/anaconda3/envs/RL/include/python3.9 -c /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/gl/dummyshim.c -o /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/gl/dummyshim.o -fopenmp -w creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/lib.macosx-11.1-arm64-3.9 creating /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/lib.macosx-11.1-arm64-3.9/mujoco_py /opt/homebrew/bin/gcc-11 -bundle -undefined dynamic_lookup -Wl,-rpath,/Users/jack/opt/anaconda3/envs/RL/lib -L/Users/jack/opt/anaconda3/envs/RL/lib -L/Users/jack/opt/anaconda3/envs/RL/lib -Wl,-rpath,/Users/jack/opt/anaconda3/envs/RL/lib -L/Users/jack/opt/anaconda3/envs/RL/lib /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/cymj.o /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/temp.macosx-11.1-arm64-3.9/Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/gl/dummyshim.o -L/Users/jack/.mujoco/mujoco210/bin -Wl,-rpath,/Users/jack/.mujoco/mujoco210/bin -lmujoco210 -lglfw.3 -o /Users/jack/opt/anaconda3/envs/RL/lib/python3.9/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_39_macextensionbuilder/lib.macosx-11.1-arm64-3.9/mujoco_py/cymj.cpython-39-darwin.so -fopenmp ### ld: warning: dylib (/Users/jack/.mujoco/mujoco210/bin/libglfw.3.dylib) was built for newer macOS version (12.0) than being linked (11.1)

zhuyuanyang avatar Jul 13 '22 14:07 zhuyuanyang

This comment seems to be working. Can we at least include it in the README file so people can find it easily?

alper111 avatar Nov 23 '22 08:11 alper111

Import error. Trying to rebuild mujoco_py. running build_ext Traceback (most recent call last): File "", line 1, in File "/Users/amineelblidi/Documents/Bachlor vorbereitung/code/PGMORL/.env/lib/python3.8/site-packages/mujoco_py/init.py", line 2, in from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException File "/Users/amineelblidi/Documents/Bachlor vorbereitung/code/PGMORL/.env/lib/python3.8/site-packages/mujoco_py/builder.py", line 504, in cymj = load_cython_ext(mujoco_path) File "/Users/amineelblidi/Documents/Bachlor vorbereitung/code/PGMORL/.env/lib/python3.8/site-packages/mujoco_py/builder.py", line 111, in load_cython_ext mod = load_dynamic_ext('cymj', cext_so_path) File "/Users/amineelblidi/Documents/Bachlor vorbereitung/code/PGMORL/.env/lib/python3.8/site-packages/mujoco_py/builder.py", line 130, in load_dynamic_ext return loader.load_module() ImportError: dlopen(/Users/amineelblidi/Documents/Bachlor vorbereitung/code/PGMORL/.env/lib/python3.8/site-packages/mujoco_py/generated/cymj_2.1.2.14_38_macextensionbuilder_38.so, 0x0002): symbol not found in flat namespace '_mjcb_act_bias'

you know why i get this erorr, i have a mac M1 pro

amine0el avatar Apr 28 '23 12:04 amine0el