问题:
ERROR: Failed building wheel for mujoco-py
Failed to build mujoco-py
ERROR: Could not build wheels for mujoco-py, which is required to install pyproject.toml-based projects
起因:
一开始我使用这个命令安装pip install mujoco_py
,应该下载的是最新版的mujoco_py
提示一堆话:
python main.py --algo=hjdqn --env=HalfCheetah-v2 --max_iter=1e6
You appear to be missing MuJoCo. We expected to find the file here: /home/zhouy24/.mujoco/mujoco210
This package only provides python bindings, the library must be installed separately.
Please follow the instructions on the README to install MuJoCo
https://github.com/openai/mujoco-py#install-mujoco
Which can be downloaded from the website
https://www.roboti.us/index.html
Traceback (most recent call last):
File "main.py", line 1, in <module>
from algorithms.ddpg.ddpg import run_ddpg
File "/data/zhouy24Files/HJDQN/HJQ/algorithms/ddpg/ddpg.py", line 4, in <module>
import mujoco_py
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/site-packages/mujoco_py/__init__.py", line 2, in <module>
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/site-packages/mujoco_py/builder.py", line 503, in <module>
mujoco_path = discover_mujoco()
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/site-packages/mujoco_py/utils.py", line 78, in discover_mujoco
raise Exception(message)
Exception:
You appear to be missing MuJoCo. We expected to find the file here: /home/zhouy24/.mujoco/mujoco210
This package only provides python bindings, the library must be installed separately.
Please follow the instructions on the README to install MuJoCo
https://github.com/openai/mujoco-py#install-mujoco
Which can be downloaded from the website
https://www.roboti.us/index.html
这里简要说明期望:mujoco210
You appear to be missing MuJoCo. We expected to find the file here: /home/zhouy24/.mujoco/mujoco210
查看了下应该是环境问题,发现期望的 MuJoCo 版本(即 mujoco210)通常与 mujoco_py 的版本相关。
对于mujoco_py 版本:较新的 mujoco_py 版本(例如 2.1 及以上)可能只支持 MuJoCo 2.1。如果你安装了较新的 mujoco_py,但只安装了 MuJoCo 2.0,系统就会找不到对应的版本,导致错误提示。
但是我安装的就是2.0
于是我就想着指定个低点的版本,环境说是mujoco-py 2.0.2,我就选了2.0.2.13版本
然后就出现一堆问题:
(HJDQN) zhouy24@RL-DSlab:~$ pip install mujoco_py==2.0.2.13
Collecting mujoco_py==2.0.2.13
Using cached mujoco-py-2.0.2.13.tar.gz (792 kB)
Installing build dependencies ... done
WARNING: Missing build requirements in pyproject.toml for mujoco_py==2.0.2.13 from https://files.pythonhosted.org/packages/2f/48/b108057c1a23c8da9f4cdc7a7c46ab7cec49c3563c0706d50f2527de6ba0/mujoco-py-2.0.2.13.tar.gz#sha256=d6ae66276b565af9063597fda70683a89c7356290f5ac3961b794ee90ec50eea.
WARNING: The project does not specify a build backend, and pip cannot fall back to setuptools without 'wheel'.
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: glfw>=1.4.0 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.13) (2.7.0)
Requirement already satisfied: imageio>=2.1.2 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.13) (2.15.0)
Requirement already satisfied: cffi>=1.10 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.13) (1.15.1)
Requirement already satisfied: Cython>=0.27.2 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.13) (3.0.11)
Requirement already satisfied: fasteners~=0.15 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.13) (0.19)
Requirement already satisfied: numpy>=1.11 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.13) (1.19.5)
Requirement already satisfied: pycparser in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from cffi>=1.10->mujoco_py==2.0.2.13) (2.21)
Requirement already satisfied: pillow>=8.3.2 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from imageio>=2.1.2->mujoco_py==2.0.2.13) (8.4.0)
Building wheels for collected packages: mujoco-py
Building wheel for mujoco-py (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /home/zhouy24/miniconda3/envs/HJDQN/bin/python3.6 /home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmpvd7diq0b
cwd: /tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4
Complete output (91 lines):
running bdist_wheel
running build
performance hint: 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: 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
^
------------------------------------------------------------
mujoco_py/cymj.pyx:92:23: Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of 'c_warning_callback'.
Error compiling Cython file:
------------------------------------------------------------
...
See c_warning_callback, which is the C wrapper to the user defined function
'''
global py_error_callback
global mju_user_error
py_error_callback = err_callback
mju_user_error = c_error_callback
^
------------------------------------------------------------
mujoco_py/cymj.pyx:127:21: Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of 'c_error_callback'.
Removing old mujoco_py cext /tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/generated/cymj_2.0.2.13_36_linuxcpuextensionbuilder_36.so
Compiling /tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/cymj.pyx
Traceback (most recent call last):
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 262, in build_wheel
metadata_directory)
File "/tmp/pip-build-env-91o0qevb/overlay/lib/python3.6/site-packages/setuptools/build_meta.py", line 231, in build_wheel
wheel_directory, config_settings)
File "/tmp/pip-build-env-91o0qevb/overlay/lib/python3.6/site-packages/setuptools/build_meta.py", line 215, in _build_with_temp_dir
self.run_setup()
File "/tmp/pip-build-env-91o0qevb/overlay/lib/python3.6/site-packages/setuptools/build_meta.py", line 268, in run_setup
self).run_setup(setup_script=setup_script)
File "/tmp/pip-build-env-91o0qevb/overlay/lib/python3.6/site-packages/setuptools/build_meta.py", line 158, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 51, in <module>
'Programming Language :: Python :: 3 :: Only',
File "/tmp/pip-build-env-91o0qevb/overlay/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-build-env-91o0qevb/normal/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 299, in run
self.run_command('build')
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/zhouy24/miniconda3/envs/HJDQN/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "setup.py", line 29, in run
import mujoco_py # noqa: force build
File "/tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/__init__.py", line 3, in <module>
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/builder.py", line 510, in <module>
cymj = load_cython_ext(mujoco_path)
File "/tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/builder.py", line 105, in load_cython_ext
cext_so_path = builder.build()
File "/tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/builder.py", line 221, in build
built_so_file_path = self._build_impl()
File "/tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/builder.py", line 273, in _build_impl
so_file_path = super()._build_impl()
File "/tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/builder.py", line 234, in _build_impl
dist.ext_modules = cythonize([self.extension])
File "/tmp/pip-build-env-91o0qevb/overlay/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
cythonize_one(*args)
File "/tmp/pip-build-env-91o0qevb/overlay/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /tmp/pip-install-_xct9sqd/mujoco-py_80b9891289254647b90a6b144834bee4/mujoco_py/cymj.pyx
----------------------------------------
ERROR: Failed building wheel for mujoco-py
Failed to build mujoco-py
ERROR: Could not build wheels for mujoco-py, which is required to install pyproject.toml-based projects
再次降低版本:pip install mujoco_py==2.0.2.8
发现成功
(HJDQN) zhouy24@RL-DSlab:~$ pip install mujoco_py==2.0.2.8
Collecting mujoco_py==2.0.2.8
Using cached mujoco_py-2.0.2.8-py3-none-any.whl (4.0 MB)
Requirement already satisfied: cffi>=1.10 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.8) (1.15.1)
Requirement already satisfied: fasteners~=0.15 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.8) (0.19)
Requirement already satisfied: numpy>=1.11 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.8) (1.19.5)
Requirement already satisfied: imageio>=2.1.2 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.8) (2.15.0)
Requirement already satisfied: glfw>=1.4.0 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.8) (2.7.0)
Requirement already satisfied: Cython>=0.27.2 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from mujoco_py==2.0.2.8) (3.0.11)
Requirement already satisfied: pycparser in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from cffi>=1.10->mujoco_py==2.0.2.8) (2.21)
Requirement already satisfied: pillow>=8.3.2 in ./miniconda3/envs/HJDQN/lib/python3.6/site-packages (from imageio>=2.1.2->mujoco_py==2.0.2.8) (8.4.0)
Installing collected packages: mujoco-py
Attempting uninstall: mujoco-py
Found existing installation: mujoco-py 2.1.2.14
Uninstalling mujoco-py-2.1.2.14:
Successfully uninstalled mujoco-py-2.1.2.14
Successfully installed mujoco-py-2.0.2.8