gym icon indicating copy to clipboard operation
gym copied to clipboard

[Bug Report] Dependency error - box2D

Open drjoeCV opened this issue 1 year ago • 6 comments

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

  • google colab
  • conda install on M2 mac
  • pip install on M2 mac

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

drjoeCV avatar Aug 16 '23 18:08 drjoeCV

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

pseudo-rnd-thoughts avatar Aug 16 '23 20:08 pseudo-rnd-thoughts

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 avatar Aug 16 '23 20:08 drjoeCV

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

drjoeCV avatar Aug 16 '23 20:08 drjoeCV

If you read the whole error when install box2d, you will see that it most likely says error: command swig.exe failed

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

pseudo-rnd-thoughts avatar Aug 17 '23 14:08 pseudo-rnd-thoughts

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.

drjoeCV avatar Aug 17 '23 14:08 drjoeCV

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.

Akram-Ashyani avatar Mar 25 '24 02:03 Akram-Ashyani