openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.83k stars 810 forks source link

Can't run examples due to library linking issue (Ubuntu 20.04) #698

Closed archielee closed 2 years ago

archielee commented 2 years ago

Describe the bug In a fresh virtualenv, I am unable to run the body_interaction example due to linking errors while building the Cython extension

To Reproduce

Expected behavior Script should run

Error Messages

Compiling /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/cymj.pyx because it depends on /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/pxd/mujoco.pxd.
[1/1] Cythonizing /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/cymj.pyx
running build_ext
building 'mujoco_py.cymj' extension
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8/site-packages
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/gl
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Ivenv/lib/python3.8/site-packages/mujoco_py -I/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py -I/home/archie/.mujoco/mujoco210/include -I/home/archie/trail/test/venv/lib/python3.8/site-packages/numpy/core/include -I/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/vendor/egl -I/home/archie/trail/test/venv/include -I/usr/include/python3.8 -c /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/cymj.c -o /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/cymj.o -fopenmp -w
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Ivenv/lib/python3.8/site-packages/mujoco_py -I/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py -I/home/archie/.mujoco/mujoco210/include -I/home/archie/trail/test/venv/lib/python3.8/site-packages/numpy/core/include -I/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/vendor/egl -I/home/archie/trail/test/venv/include -I/usr/include/python3.8 -c /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/gl/eglshim.c -o /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/gl/eglshim.o -fopenmp -w
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/lib.linux-x86_64-3.8
creating /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/lib.linux-x86_64-3.8/mujoco_py
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/cymj.o /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/temp.linux-x86_64-3.8/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/gl/eglshim.o -L/home/archie/.mujoco/mujoco210/bin -Wl,--enable-new-dtags,-R/home/archie/.mujoco/mujoco210/bin -lmujoco210 -lglewegl -o /home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_linuxgpuextensionbuilder/lib.linux-x86_64-3.8/mujoco_py/cymj.cpython-38-x86_64-linux-gnu.so -fopenmp
/usr/bin/ld: cannot find -lmujoco210
/usr/bin/ld: cannot find -lglewegl
collect2: error: ld returned 1 exit status
Traceback (most recent call last):
  File "/usr/lib/python3.8/distutils/unixccompiler.py", line 215, in link
    self.spawn(linker + ld_args)
  File "/usr/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "/usr/lib/python3.8/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/usr/lib/python3.8/distutils/spawn.py", line 157, in _spawn_posix
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "body_interaction.py", line 10, in <module>
    from mujoco_py import load_model_from_xml, MjSim, MjViewer
  File "/home/archie/trail/test/venv/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 "/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/builder.py", line 504, in <module>
    cymj = load_cython_ext(mujoco_path)
  File "/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/builder.py", line 110, in load_cython_ext
    cext_so_path = builder.build()
  File "/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/builder.py", line 226, in build
    built_so_file_path = self._build_impl()
  File "/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/builder.py", line 296, in _build_impl
    so_file_path = super()._build_impl()
  File "/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/builder.py", line 249, in _build_impl
    dist.run_commands()
  File "/usr/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/home/archie/trail/test/venv/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "/usr/lib/python3.8/distutils/command/build_ext.py", line 340, in run
    self.build_extensions()
  File "/home/archie/trail/test/venv/lib/python3.8/site-packages/mujoco_py/builder.py", line 149, in build_extensions
    build_ext.build_extensions(self)
  File "/home/archie/trail/test/venv/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
    _build_ext.build_ext.build_extensions(self)
  File "/usr/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
    self._build_extensions_serial()
  File "/usr/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
    self.build_extension(ext)
  File "/usr/lib/python3.8/distutils/command/build_ext.py", line 550, in build_extension
    self.compiler.link_shared_object(
  File "/usr/lib/python3.8/distutils/ccompiler.py", line 713, in link_shared_object
    self.link(CCompiler.SHARED_OBJECT, objects,
  File "/usr/lib/python3.8/distutils/unixccompiler.py", line 217, in link
    raise LinkError(msg)
distutils.errors.LinkError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Specifically, it looks like the linker is failing:

/usr/bin/ld: cannot find -lmujoco210
/usr/bin/ld: cannot find -lglewegl

Desktop (please complete the following information):

Environment

Additional context The builder.py script tells me to add /usr/lib/nvidia to the library path but the folder is empty, I'm not sure if the NVIDIA driver installer in Ubuntu 20.04 installs there anymore. I only have a file named alternate-install-available in there

archielee commented 2 years ago

I found a workaround for the problem but I believe it's related to the manually_link_libraries() function.

mujoco210 libraries are no longer in mujoco210/bin like in v2.0.0, but in mujoco210/lib. I made symlinks to all the library files in bin and then renamed the libmujoco.so symlink to libmujoco210.so and it seemed to have fixed the issue. This is definitely more a hacky workaround though

archielee commented 2 years ago

Apologies, closing this issue. I think I downloaded Mujoco 2.1.1 instead of 2.1.0 which breaks compatibility