如果你一开始就报错gcc
的问题的话,我建议你首先看官方的解决办法:
整个的报错记录如下:
>>> import mujoco_py running build_ext building 'mujoco_py.cymj' extension gcc -pthread -B /home/hzq/anaconda3/envs/TianChi/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Ianaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py -I/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py -I/home/hzq/.mujoco/mujoco200/include -I/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/numpy/core/include -I/home/hzq/anaconda3/envs/TianChi/include/python3.6m -c /home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/cymj.c -o /home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/generated/_pyxbld_2.0.2.13_36_linuxcpuextensionbuilder/temp.linux-x86_64-3.6/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/cymj.o -fopenmp -w gcc -pthread -B /home/hzq/anaconda3/envs/TianChi/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Ianaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py -I/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py -I/home/hzq/.mujoco/mujoco200/include -I/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/numpy/core/include -I/home/hzq/anaconda3/envs/TianChi/include/python3.6m -c /home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/gl/osmesashim.c -o /home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/generated/_pyxbld_2.0.2.13_36_linuxcpuextensionbuilder/temp.linux-x86_64-3.6/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/gl/osmesashim.o -fopenmp -w gcc -pthread -shared -B /home/hzq/anaconda3/envs/TianChi/compiler_compat -L/home/hzq/anaconda3/envs/TianChi/lib -Wl,-rpath=/home/hzq/anaconda3/envs/TianChi/lib -Wl,--no-as-needed -Wl,--sysroot=/ /home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/generated/_pyxbld_2.0.2.13_36_linuxcpuextensionbuilder/temp.linux-x86_64-3.6/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/cymj.o /home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/generated/_pyxbld_2.0.2.13_36_linuxcpuextensionbuilder/temp.linux-x86_64-3.6/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/gl/osmesashim.o -L/home/hzq/.mujoco/mujoco200/bin -Wl,-R/home/hzq/.mujoco/mujoco200/bin -lmujoco200 -lglewosmesa -lOSMesa -lGL -o /home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/generated/_pyxbld_2.0.2.13_36_linuxcpuextensionbuilder/lib.linux-x86_64-3.6/mujoco_py/cymj.cpython-36m-x86_64-linux-gnu.so -fopenmp /home/hzq/anaconda3/envs/TianChi/compiler_compat/ld: cannot find -lGL collect2: error: ld returned 1 exit status Traceback (most recent call last): File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/unixccompiler.py", line 197, in link self.spawn(linker + ld_args) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/__init__.py", line 3, in <module> from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/builder.py", line 510, in <module> cymj = load_cython_ext(mujoco_path) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/builder.py", line 105, in load_cython_ext cext_so_path = builder.build() File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/builder.py", line 221, in build built_so_file_path = self._build_impl() File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/builder.py", line 273, in _build_impl so_file_path = super()._build_impl() File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/builder.py", line 244, in _build_impl dist.run_commands() File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/mujoco_py-2.0.2.13-py3.6.egg/mujoco_py/builder.py", line 144, in build_extensions build_ext.build_extensions(self) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions _build_ext.build_ext.build_extensions(self) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/command/build_ext.py", line 558, in build_extension target_lang=language) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/ccompiler.py", line 717, in link_shared_object extra_preargs, extra_postargs, build_temp, target_lang) File "/home/hzq/anaconda3/envs/TianChi/lib/python3.6/distutils/unixccompiler.py", line 199, in link raise LinkError(msg) distutils.errors.LinkError: command 'gcc' failed with exit status 1
这里我就定位到:
/home/hzq/anaconda3/envs/TianChi/compiler_compat/ld: cannot find -lGL collect2: error: ld returned 1 exit status
然后看gcc报错,参考这篇帖子:https://github.com/ContinuumIO/anaconda-issues/issues/11152
rename /home/eva/miniconda3/compiler_compat/ld to ld_old. or just delete it.
把这个什么ld给重命名了,发现还是没啥用。然后又看issue:https://github.com/openai/mujoco-py/issues/374。发现需要重装
apt install libgl1-mesa-glx --reinstall
重装一下之后就好了。
后续
我还有尝试过:
https://github.com/cocodataset/cocoapi/issues/94