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

Mujoco-py is incompatible with cython 3 (Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil)

Open pseudo-rnd-thoughts opened this issue 2 years ago • 36 comments

Describe the bug Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'

To Reproduce Install cpython 3.0.0, import mujoco-py

Expected behavior mujoco-py compiles

Error Messages From gymnasium's CI

tests/wrappers/test_passive_env_checker.py:9: in <module>
    from tests.envs.test_envs import PASSIVE_CHECK_IGNORE_WARNING
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
../lib/python3.8/site-packages/_pytest/assertion/rewrite.py:168: in exec_module
    exec(co, module.__dict__)
tests/envs/test_envs.py:10: in <module>
    from tests.envs.utils import (
tests/envs/utils.py:34: in <module>
    all_testing_initialised_envs: List[Optional[gym.Env]] = [
tests/envs/utils.py:35: in <listcomp>
    try_make_env(env_spec) for env_spec in gym.envs.registry.values()
tests/envs/utils.py:22: in try_make_env
    return env_spec.make(disable_env_checker=True).unwrapped
gymnasium/envs/registration.py:130: in make
    return make(self, **kwargs)
gymnasium/envs/registration.py:756: in make
    env_creator = load_env_creator(env_spec.entry_point)
gymnasium/envs/registration.py:545: in load_env_creator
    mod = importlib.import_module(mod_name)
../lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
gymnasium/envs/mujoco/__init__.py:1: in <module>
    from gymnasium.envs.mujoco.mujoco_env import MujocoEnv, MuJocoPyEnv  # isort:skip
gymnasium/envs/mujoco/mujoco_env.py:13: in <module>
    import mujoco_py
/mujoco-py/mujoco_py/__init__.py:2: in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
/mujoco-py/mujoco_py/builder.py:504: in <module>
    cymj = load_cython_ext(mujoco_path)
/mujoco-py/mujoco_py/builder.py:110: in load_cython_ext
    cext_so_path = builder.build()
/mujoco-py/mujoco_py/builder.py:226: in build
    built_so_file_path = self._build_impl()
/mujoco-py/mujoco_py/builder.py:278: in _build_impl
    so_file_path = super()._build_impl()
/mujoco-py/mujoco_py/builder.py:239: in _build_impl
    dist.ext_modules = cythonize([self.extension])
../lib/python3.8/site-packages/Cython/Build/Dependencies.py:1134: in cythonize
    cythonize_one(*args)
../lib/python3.8/site-packages/Cython/Build/Dependencies.py:1301: in cythonize_one
    raise CompileError(None, pyx_file)
E   Cython.Compiler.Errors.CompileError: /mujoco-py/mujoco_py/cymj.pyx
------------------------------- Captured stdout --------------------------------
Compiling /mujoco-py/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /mujoco-py/mujoco_py/cymj.pyx
------------------------------- Captured stderr --------------------------------

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/mujoco_py/cymj.pyx:92:23: Cannot assign type 'void (const char *) except * 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
                     ^
------------------------------------------------------------

/mujoco-py/mujoco_py/cymj.pyx:127:21: Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'

pseudo-rnd-thoughts avatar Jul 17 '23 21:07 pseudo-rnd-thoughts

Facing the same issue.

JayanthRR avatar Jul 17 '23 23:07 JayanthRR

Same issue on my side

ChengDaHaI avatar Jul 18 '23 02:07 ChengDaHaI

I solved it with pip install "cython<3"

pseudo-rnd-thoughts avatar Jul 18 '23 07:07 pseudo-rnd-thoughts

Same issue on my side

fyqqyf avatar Jul 20 '23 14:07 fyqqyf

Same

AdilZouitine avatar Jul 20 '23 14:07 AdilZouitine

TYSM for figuring this out, wasted 3 hours today

ezhang7423 avatar Jul 21 '23 01:07 ezhang7423

TYSM for figuring this out, wasted 3 hours today

4 hours and 5 times recreate virtual environments 😇

fyqqyf avatar Jul 21 '23 02:07 fyqqyf

already have Cython==0.29.36 but the same error exists when pip install mujoco_py==2.0.2.7

alafumee avatar Jul 21 '23 15:07 alafumee

already have Cython==0.29.36 but the same error exists when pip install mujoco_py==2.0.2.7

Same

qodfathr avatar Jul 21 '23 19:07 qodfathr

I am using mujoco-py==1.50.1.68

ezhang7423 avatar Jul 22 '23 06:07 ezhang7423

I cannot tell if this is directly related to cython 3 or not. I have 0.29.36 installed (and I've tried many versions from 0.27.2 on up) and the same error is occurring even on mujoco_py==2.0.2.13. I tried to determine if a patch to the underlying c++ compiler was at fault, but that does not seem to be the case.

qodfathr avatar Jul 22 '23 15:07 qodfathr

I cannot tell if this is directly related to cython 3 or not. I have 0.29.36 installed (and I've tried many versions from 0.27.2 on up) and the same error is occurring even on mujoco_py==2.0.2.13. I tried to determine if a patch to the underlying c++ compiler was at fault, but that does not seem to be the case.

I would be surprised as our CI should be failing if this was true but it is not failing with cython < 3 also if you are getting the same issue with nogil in the error then this is a cython >= 3 thing

pseudo-rnd-thoughts avatar Jul 22 '23 16:07 pseudo-rnd-thoughts

I would be surprised as our CI should be failing if this was true but it is not failing with cython < 3 also if you are getting the same issue with nogil in the error then this is a cython >= 3 thing

I now have it working with mujoco_py==2.0.2.5, but no later 2.0.2.x releases. I see that 2.0.2.5 is probably the last "official" 2.0.2 release, but PyPi is misleading.

qodfathr avatar Jul 22 '23 18:07 qodfathr

I was able to use

pip install 'cython<3'

to compile mujoco-py 2.1.2.14 on Ubuntu 22.04, Python 3.8

reginald-mclean avatar Jul 25 '23 20:07 reginald-mclean

same, cython<3 not works for me

Zebin-Li avatar Jul 25 '23 22:07 Zebin-Li

I was facing the similar issue in numpy-1.23.3 build with cython 3.0.0, using pip3 install "cython<3" worked for me.

zuhu2195 avatar Jul 31 '23 07:07 zuhu2195

I solved it with pip install "cython<3"

Does not work for me, I am trying to install safety-gym.

mujoco200 mujoco-py 2.1.2.14 Ubuntu 20.04 Python 3.6

Anyone found any other ways to resolve?

TIA

HasarinduPerera avatar Aug 03 '23 06:08 HasarinduPerera

What is your current Cython version?

zuhu2195 avatar Aug 03 '23 07:08 zuhu2195

What is your current Cython version?

Cython 0.29.36

HasarinduPerera avatar Aug 03 '23 07:08 HasarinduPerera

can you try updating your python to a higher version like 3.8.

zuhu2195 avatar Aug 03 '23 07:08 zuhu2195

can you try updating your python to a higher version like 3.8.

No progress.

HasarinduPerera avatar Aug 03 '23 07:08 HasarinduPerera

I would be surprised as our CI should be failing if this was true but it is not failing with cython < 3 also if you are getting the same issue with nogil in the error then this is a cython >= 3 thing

I now have it working with mujoco_py==2.0.2.5, but no later 2.0.2.x releases. I see that 2.0.2.5 is probably the last "official" 2.0.2 release, but PyPi is misleading.

This Worked!

HasarinduPerera avatar Aug 03 '23 09:08 HasarinduPerera

Surprisingly, uninstalling Cython fixed the problem for me.

Python: 3.8 gymnasium==0.29.1 mujoco==2.3.7

Mujoco version: 2.10

mynkpl1998 avatar Sep 02 '23 13:09 mynkpl1998

  1. Add a compiler directive " compiler_directives={'legacy_implicit_noexcept': True}" to the line 239 of mujoco_py/builder.py
 def _build_impl(self):
        dist = Distribution({
            "script_name": None,
            "script_args": ["build_ext"]
        })
        dist.ext_modules = cythonize([self.extension],compiler_directives={'legacy_implicit_noexcept': True})
  1. Update Cython to the latest 3.0.2 version.
pip install -U Cython
  1. The reasons can be found here https://github.com/scikit-learn/scikit-learn/issues/25609 https://github.com/cython/cython/issues/5637

harryting-yiting avatar Sep 09 '23 06:09 harryting-yiting

I would be surprised as our CI should be failing if this was true but it is not failing with cython < 3 also if you are getting the same issue with nogil in the error then this is a cython >= 3 thing

I now have it working with mujoco_py==2.0.2.5, but no later 2.0.2.x releases. I see that 2.0.2.5 is probably the last "official" 2.0.2 release, but PyPi is misleading.

This Worked!

It works for my.

zerlinwang avatar Sep 16 '23 08:09 zerlinwang

I am use mujoco210 and mujoco_py==2.1.2.14 This command helps for the cymj error:

I solved it with pip install "cython<3"

Thanks!

glorgao avatar Sep 19 '23 16:09 glorgao

I solved it with pip install "cython<3"

Does not work for me, I am trying to install safety-gym.

mujoco200 mujoco-py 2.1.2.14 Ubuntu 20.04 Python 3.6

Anyone found any other ways to resolve?

TIA

mujoco-py 2.1.2.14 and mujoco200 are not match. Use mujoco_py 2.1.2.14 with mujoco210, or mujoco>2.0 <2.1 with mujoco200.

glorgao avatar Sep 19 '23 16:09 glorgao

  1. Add a compiler directive " compiler_directives={'legacy_implicit_noexcept': True}" to the line 239 of mujoco_py/builder.py
 def _build_impl(self):
        dist = Distribution({
            "script_name": None,
            "script_args": ["build_ext"]
        })
        dist.ext_modules = cythonize([self.extension],compiler_directives={'legacy_implicit_noexcept': True})
  1. Update Cython to the latest 3.0.2 version.
pip install -U Cython
  1. The reasons can be found here [MAINT, Cython] Implicit noexcept is deprecated in Cython 3.0 scikit-learn/scikit-learn#25609 [BUG] enum classes cannot be used in cdef class method declarations cython/cython#5637

This works for my problem. Thanks a lot.

my env:

  • Ubuntu 22.04
  • python 3.8
  • mujoco 2.1.0
  • mujoco-py 2.1.2.14
  • Cython 3.0.6

iLern avatar Nov 28 '23 11:11 iLern

  1. Add a compiler directive " compiler_directives={'legacy_implicit_noexcept': True}" to the line 239 of mujoco_py/builder.py
 def _build_impl(self):
        dist = Distribution({
            "script_name": None,
            "script_args": ["build_ext"]
        })
        dist.ext_modules = cythonize([self.extension],compiler_directives={'legacy_implicit_noexcept': True})
  1. Update Cython to the latest 3.0.2 version.
pip install -U Cython
  1. The reasons can be found here [MAINT, Cython] Implicit noexcept is deprecated in Cython 3.0 scikit-learn/scikit-learn#25609 [BUG] enum classes cannot be used in cdef class method declarations cython/cython#5637

This works for my problem. Thanks a lot.

my env:

  • Ubuntu 22.04
  • python 3.8
  • mujoco 2.1.0
  • mujoco-py 2.1.2.14
  • Cython 3.0.6

This works! Thanks

Zsk0 avatar Dec 13 '23 09:12 Zsk0

pip install Cython==3.0.0a10 works for me.

My env: Ubuntu 20.04 python 3.8.17 mujoco 2.1.0 mujoco-py 2.1.2.14

YupuLu avatar Jan 07 '24 08:01 YupuLu