DLR-RM / stable-baselines3

PyTorch version of Stable Baselines, reliable implementations of reinforcement learning algorithms.
https://stable-baselines3.readthedocs.io
MIT License
8.35k stars 1.6k forks source link

[Bug]: ModuleNotFoundError: No module named 'gymnasium.wrappers.monitoring' #1955

Closed wilhem closed 5 days ago

wilhem commented 6 days ago

🐛 Bug

I installed today the package stable_baselines3 using pip. According to pip's output, the version installed is the 2.3.2 Along with this version Gymnasium 0.29.1 was installed. Since the package shimmy was missing, I proceeded to install it using pip. Shimmy removed gymnasium 0.29.1 and installed gymnasium 1.0.0a2 instead.

Trying to import stable_baselines3 leads to the following error:


Traceback (most recent call last):
  File "/home/ubuntu/Downloads/my_project/controllers/cartpole_v2/cartpole_v2.py", line 5, in <module>
    import stable_baselines3
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/__init__.py", line 3, in <module>
    from stable_baselines3.a2c import A2C
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/a2c/__init__.py", line 1, in <module>
    from stable_baselines3.a2c.a2c import A2C
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/a2c/a2c.py", line 7, in <module>
    from stable_baselines3.common.buffers import RolloutBuffer
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/common/buffers.py", line 17, in <module>
    from stable_baselines3.common.vec_env import VecNormalize
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/common/vec_env/__init__.py", line 14, in <module>
    from stable_baselines3.common.vec_env.vec_video_recorder import VecVideoRecorder
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 4, in <module>
    from gymnasium.wrappers.monitoring import video_recorder
ModuleNotFoundError: No module named 'gymnasium.wrappers.monitoring'

To Reproduce

import stable_baselines3

Relevant log output / Error message

Traceback (most recent call last):
  File "/home/ubuntu/Downloads/my_project/controllers/cartpole_v2/cartpole_v2.py", line 5, in <module>
    import stable_baselines3
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/__init__.py", line 3, in <module>
    from stable_baselines3.a2c import A2C
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/a2c/__init__.py", line 1, in <module>
    from stable_baselines3.a2c.a2c import A2C
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/a2c/a2c.py", line 7, in <module>
    from stable_baselines3.common.buffers import RolloutBuffer
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/common/buffers.py", line 17, in <module>
    from stable_baselines3.common.vec_env import VecNormalize
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/common/vec_env/__init__.py", line 14, in <module>
    from stable_baselines3.common.vec_env.vec_video_recorder import VecVideoRecorder
  File "/home/ubuntu/Downloads/deepbots-env/lib/python3.10/site-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 4, in <module>
    from gymnasium.wrappers.monitoring import video_recorder
ModuleNotFoundError: No module named 'gymnasium.wrappers.monitoring'

System Info

Since it gives the same error as above, it does not print any information

Checklist

araffin commented 6 days ago

Hello, pip should have warned you that this version is incompatible with sb3 (we have a pr opened for gymnasium 1.0). If you re-install sb3 with the extra package, it will install the correct shimmy version (see doc).

EDIT: the PR https://github.com/DLR-RM/stable-baselines3/pull/1837

wilhem commented 6 days ago

Hello,

I looked back to the installation output of pip. That's true, it says: stable_baselines3 2.3.2 requires gymnasium<0.30,>=0.28.1, but you have gymnsasium 1.0.0a2 which is incompatible.

But why did pip install shimmy anyway? I would have used conda. With conda I do not have such problem. It ask you before installing anything.

araffin commented 5 days ago

pip doesn't enforce strict compatibility (which is handy when dependencies version ranges are wrongly specified/too tight, but can have issues like yours) and as far as i know, it has no option yet to enforce it. However, you have alternatives like pixi, uv, conda or poetry.

Closing as the original question was answered and a PR exists.