openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.58k stars 8.59k forks source link

[Bug Report] Dependency error - box2D #3240

Open drjoeCV opened 1 year ago

drjoeCV commented 1 year ago

Tried to use gymnasium on several platforms and always get unresolvable error

Code example import gymnasium as gym env = gym.make("LunarLander-v2", render_mode="human")


ModuleNotFoundError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/gym/envs/box2d/bipedal_walker.py in 14 try: ---> 15 import Box2D 16 from Box2D.b2 import (

ModuleNotFoundError: No module named 'Box2D'

During handling of the above exception, another exception occurred:

DependencyNotInstalled Traceback (most recent call last) 15 frames /usr/local/lib/python3.10/dist-packages/gym/envs/box2d/bipedal_walker.py in 23 ) 24 except ImportError: ---> 25 raise DependencyNotInstalled("box2D is not installed, run pip install gymnasium[box2d]") 26 27

DependencyNotInstalled: box2D is not installed, run pip install gymnasium[box2d]

pip install gymnasium System Info Describe the characteristic of your environment: Same error in all of these scenarios under python 3.11

Additional context Trying to fix via pip install gymnasium[box2d] fails on all three scenarios

pseudo-rnd-thoughts commented 1 year ago

What was the issue with running pip install gymnasium[box2d]? Have you installed swig?

drjoeCV commented 1 year ago

When trying to pip install gymnasium[box2d]:

Failed to build box2d-py ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects

drjoeCV commented 1 year ago

more importantly, your installation instructions do not say to install box2d so you need to fix those.

pseudo-rnd-thoughts commented 1 year ago

If you read the whole error when install box2d, you will see that it most likely says error: commandswig.exefailed

So you will lneed to install swig - https://www.swig.org/download.html For example - https://github.com/openai/gym/issues/2795

drjoeCV commented 1 year ago

swig fails to install as well: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

The real problem is that not all of the requirements are included in this package to properly install using pip or condo. You shouldn't make the user have to figure out what you are missing.

Akram-Ashyani commented 6 months ago

Dear @drjoeCV , After successfully installing SWIG and the gym[box2d] package, I encountered an issue where my Jupyter Notebook was unable to recognize the environment when attempting to run it. The specific error messages indicated problems with importing modules from the Box2D package, culminating in a ModuleNotFoundError for _Box2D, and subsequently a DependencyNotInstalled error suggesting that box2D was not installed, despite my earlier successful installation.

The traceback provided detailed information about the import failures, with errors pointing to missing shared object files and unresolvable module imports within the Python environment, specifically Python version 3.7.

To resolve this issue, I found a solution that worked for me in a GitHub issue thread. It involved installing additional packages beyond what I had initially set up. By running pip install box2d pygame, I was able to address the dependencies and successfully initialize the environment within my Jupyter notebook. This solution was sourced from a discussion in an OpenAI Gym issue: https://github.com/openai/gym/issues/2795.

I hope this solution will be helpful for you.