sail-sg / envpool

C++-based high-performance parallel environment execution engine (vectorized env) for general RL environments.
https://envpool.readthedocs.io
Apache License 2.0
1.09k stars 100 forks source link

[BUG] TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases #166

Closed Trinkle23897 closed 2 years ago

Trinkle23897 commented 2 years ago

To Reproduce

This happens in gym==0.25.0 for all python version.

$ pip install gym envpool --upgrade
$ python -c "import envpool"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/trinkle/.local/lib/python3.8/site-packages/envpool/__init__.py", line 16, in <module>
    import envpool.entry  # noqa: F401
  File "/home/trinkle/.local/lib/python3.8/site-packages/envpool/entry.py", line 16, in <module>
    import envpool.atari.registration  # noqa: F401
  File "/home/trinkle/.local/lib/python3.8/site-packages/envpool/atari/__init__.py", line 21, in <module>
    AtariEnvSpec, AtariDMEnvPool, AtariGymEnvPool = py_env(
  File "/home/trinkle/.local/lib/python3.8/site-packages/envpool/python/api.py", line 34, in py_env
    GymEnvPoolMeta(pool_name.replace("EnvPool", "GymEnvPool"), (envpool,), {}),
  File "/home/trinkle/.local/lib/python3.8/site-packages/envpool/python/gym_envpool.py", line 86, in __new__
    subcls = super().__new__(cls, name, parents, attrs)
  File "/usr/lib/python3.8/abc.py", line 85, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Expected behavior

No import error.

Reason and Possible fixes

Hot fix: pip install gym<0.25. But maybe other better way?

cc @mavenlin

mavenlin commented 2 years ago

The reason seems to be Gym added metaclass to its env. https://github.com/openai/gym/pull/2927/files Could be resolved by https://stackoverflow.com/questions/11276037/resolving-metaclass-conflicts

We may try using class GymEnvPoolMeta(ABCMeta, gym.Env.__class__) at https://github.com/sail-sg/envpool/blob/669a4e6a30de4f98b34d0deb45bb81351b8e8080/envpool/python/gym_envpool.py#L42