Open HanYuanHsu opened 10 months ago
@HanYuanHsu, have you been able to solve this problem?
@dranaju no, I modified the c_warning_callback function
in python3.10/site-packages/mujoco_py/cymj.pyx
to return an interger like the following:
cdef int c_warning_callback(const char *msg) with gil:
'''
Wraps the warning callback so we can raise exceptions.
Because callbacks can't propagate exceptions, we set a global that has
to be inspected later.
Use wrap_mujoco_warning() to check for that saved exception and
re-raise it back to the caller.
'''
global py_warning_callback
try:
(<object> py_warning_callback)(msg)
except Exception as e:
global py_warning_exception
py_warning_exception = e
return -10
Same for the c_error_callback
function. But then I got the following error:
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
^
------------------------------------------------------------
/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/cymj.pyx:94:23: Cannot assign type 'int (const char *) except? -1 nogil' to 'void (*)(const char *) noexcept nogil'
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
^
------------------------------------------------------------
/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/cymj.pyx:131:21: Cannot assign type 'int (const char *) except? -1 nogil' to 'void (*)(const char *) noexcept nogil'
Traceback (most recent call last):
File "/home/hanyuan/Desktop/d4rl_test/test.py", line 2, in <module>
import d4rl # Import required to register environments, you may need to also import the submodule
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/d4rl/__init__.py", line 14, in <module>
import d4rl.locomotion
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/d4rl/locomotion/__init__.py", line 2, in <module>
from d4rl.locomotion import ant
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/d4rl/locomotion/ant.py", line 20, in <module>
import mujoco_py
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/__init__.py", line 2, in <module>
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/builder.py", line 504, in <module>
cymj = load_cython_ext(mujoco_path)
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/builder.py", line 110, in load_cython_ext
cext_so_path = builder.build()
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/builder.py", line 226, in build
built_so_file_path = self._build_impl()
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/builder.py", line 296, in _build_impl
so_file_path = super()._build_impl()
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/builder.py", line 239, in _build_impl
dist.ext_modules = cythonize([self.extension])
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
cythonize_one(*args)
File "/home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /home/hanyuan/anaconda3/envs/d4rl/lib/python3.10/site-packages/mujoco_py/cymj.pyx
@HanYuanHsu, I've successfully managed to run this part by downgrading the Cython version to less than 3. My current Cython version is 0.29.37. To do the same, you can simply execute the command pip install 'cython<3'
.
When I tried to run the following python script
I got the following error message:
Does anyone know how to solve this? Here are the packages installed in my environment:
I have also downloaded mujoco to the folder
~/.mujoco/mujoco210
according to the instruction.