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.79k stars 810 forks source link

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

Open pseudo-rnd-thoughts opened 12 months ago

pseudo-rnd-thoughts commented 12 months ago

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'
JayanthRR commented 12 months ago

Facing the same issue.

ChengDaHaI commented 12 months ago

Same issue on my side

pseudo-rnd-thoughts commented 12 months ago

I solved it with pip install "cython<3"

fyqqyf commented 11 months ago

Same issue on my side

AdilZouitine commented 11 months ago

Same

ezhang7423 commented 11 months ago

TYSM for figuring this out, wasted 3 hours today

fyqqyf commented 11 months ago

TYSM for figuring this out, wasted 3 hours today

4 hours and 5 times recreate virtual environments 😇

alafumee commented 11 months ago

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

qodfathr commented 11 months ago

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

Same

ezhang7423 commented 11 months ago

I am using mujoco-py==1.50.1.68

qodfathr commented 11 months ago

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.

pseudo-rnd-thoughts commented 11 months ago

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

qodfathr commented 11 months ago

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.

reginald-mclean commented 11 months ago

I was able to use

pip install 'cython<3'

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

Zebin-Li commented 11 months ago

same, cython<3 not works for me

zuhu2195 commented 11 months ago

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.

HasarinduPerera commented 11 months ago

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

zuhu2195 commented 11 months ago

What is your current Cython version?

HasarinduPerera commented 11 months ago

What is your current Cython version?

Cython 0.29.36

zuhu2195 commented 11 months ago

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

HasarinduPerera commented 11 months ago

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

No progress.

HasarinduPerera commented 11 months ago

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!

mynkpl1998 commented 10 months ago

Surprisingly, uninstalling Cython fixed the problem for me.

Python: 3.8 gymnasium==0.29.1 mujoco==2.3.7

Mujoco version: 2.10

harryting-yiting commented 10 months ago
  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
zerlinwang commented 10 months ago

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.

glorgao commented 9 months ago

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 commented 9 months ago

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.

iLern commented 7 months ago
  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:

Zsk0 commented 7 months ago
  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

YupuLu commented 6 months ago

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

ZhaoRunyi commented 2 months ago
  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 cause me "AttributeError: module ‘mujoco_py’ has no attribute 'utils’" after following the instructions from 4. https://blog.csdn.net/shouchen1/article/details/130002566 (it 's a Chinese blog), which is make chage to the test code provided by the official website:

import mujoco_py 
from mujoco_py import utils # this line is added
import os
mj_path = utils.discover_mujoco() # change mujoco.utils->utils
xml_path = os.path.join(mj_path, 'model', 'humanoid.xml')
model = mujoco_py.load_model_from_path(xml_path)
sim = mujoco_py.MjSim(model)

the problem solved.

MSiba commented 1 month ago

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

Did you find a workaround for this?

dhruvmsheth commented 2 weeks ago

Here are the steps that worked for me:

pip install "cython<3"
conda install gxx_linux-64
sudo ln -sf /usr/bin/gcc /home/dhruvstra/anaconda3/envs/argus/bin/x86_64-conda-linux-gnu-cc

The /home/dhruvstra/anaconda3/envs/argus/bin/x86_64-conda-linux-gnu-cc should be your path to where conda linux gnu is installed. It might be located at usr/bin/

and the most important one was: conda install -c conda-forge gcc=12.1.0