Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] Installing box2d on colab #662

Closed
qsimeon opened this issue Aug 9, 2023 · 5 comments · Fixed by #683 or #1009
Closed

[Bug Report] Installing box2d on colab #662

qsimeon opened this issue Aug 9, 2023 · 5 comments · Fixed by #683 or #1009
Labels
bug Something isn't working

Comments

@qsimeon
Copy link

qsimeon commented Aug 9, 2023

Describe the bug

It's not great that the example on the documentation home page does not work. I tried running that example (copy-pasted exactly from the home page) in a Google Colab notebook (after installing gymnasium with !pip install gymnasium) and was immediately faced with this error: "DependencyNotInstalled: Box2D is not installed, run pip install gymnasium[box2d]".
When I follow the suggestion and !pip install gymnasium[box2d] run in new code cell, the installation fails due this this error: "ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects".

Code example

!pip install gymnasium
Collecting gymnasium
  Using cached gymnasium-0.29.0-py3-none-any.whl (953 kB)
Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from gymnasium) (1.23.5)
Requirement already satisfied: cloudpickle>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from gymnasium) (2.2.1)
Requirement already satisfied: typing-extensions>=4.3.0 in /usr/local/lib/python3.10/dist-packages (from gymnasium) (4.7.1)
Collecting farama-notifications>=0.0.1 (from gymnasium)
  Using cached Farama_Notifications-0.0.4-py3-none-any.whl (2.5 kB)
Installing collected packages: farama-notifications, gymnasium
Successfully installed farama-notifications-0.0.4 gymnasium-0.29.0
import gymnasium as gym
env = gym.make("LunarLander-v2", render_mode="human")
observation, info = env.reset(seed=42)
for _ in range(1000):
   action = env.action_space.sample()  # this is where you would insert your policy
   observation, reward, terminated, truncated, info = env.step(action)

   if terminated or truncated:
      observation, info = env.reset()

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

ModuleNotFoundError: No module named 'Box2D'

The above exception was the direct cause of the following exception:

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

DependencyNotInstalled: Box2D is not installed, run `pip install gymnasium[box2d]`
!pip install gymnasium[box2d]
Requirement already satisfied: gymnasium[box2d] in /usr/local/lib/python3.10/dist-packages (0.29.0)
Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from gymnasium[box2d]) (1.23.5)
Requirement already satisfied: cloudpickle>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from gymnasium[box2d]) (2.2.1)
Requirement already satisfied: typing-extensions>=4.3.0 in /usr/local/lib/python3.10/dist-packages (from gymnasium[box2d]) (4.7.1)
Requirement already satisfied: farama-notifications>=0.0.1 in /usr/local/lib/python3.10/dist-packages (from gymnasium[box2d]) (0.0.4)
Collecting box2d-py==2.3.5 (from gymnasium[box2d])
  Using cached box2d-py-2.3.5.tar.gz (374 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: pygame>=2.1.3 in /usr/local/lib/python3.10/dist-packages (from gymnasium[box2d]) (2.5.0)
Collecting swig==4.* (from gymnasium[box2d])
  Using cached swig-4.1.1-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.8 MB)
Building wheels for collected packages: box2d-py
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for box2d-py (setup.py) ... error
  ERROR: Failed building wheel for box2d-py
  Running setup.py clean for box2d-py
Failed to build box2d-py
ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects


### System info

Google Colab environment. 
Python 3.10.12. 
Gymnasium installed using `!pip install gymnasium`. 
gymnasium.__version__ == 0.29.0

### Additional context

_No response_

### Checklist

- [X] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/Gymnasium/issues) in the repo
@qsimeon qsimeon added the bug Something isn't working label Aug 9, 2023
@pseudo-rnd-thoughts pseudo-rnd-thoughts changed the title [Bug Report] Bug title [Bug Report] Installing box2d on colab Aug 9, 2023
@robertoschiavone
Copy link
Contributor

Not an actual bug, but it's more a lack of (critical, in my opinion) documentation. To run the example (or any env that requires box2d) in a Google Colab notebook, you need to install swig first:

!apt-get install swig
!pip install gymnasium[box2d]

@btjanaka
Copy link
Contributor

btjanaka commented Aug 21, 2023

@robertoschiavone @pseudo-rnd-thoughts I think the bug is a lot simpler than this. box2d does seem to depend on swig, but the dependency is in the wrong order, i.e., swig is placed after box2d:

box2d = ["box2d-py ==2.3.5", "pygame >=2.1.3", "swig ==4.*"]
This means that box2d is installed before swig even though it depends on swig to be built.

I tried this in #677 but it actually does not work because it seems swig needs to be installed beforehand so that its executable can be called.

@pseudo-rnd-thoughts
Copy link
Member

@robertoschiavone Would you be able to make a PR to improve the documentation. You should just need to modify the box2d environment's docstring

btjanaka added a commit to icaros-usc/pyribs that referenced this issue Aug 21, 2023
…347)

## Description

fixes #346 

Also encountered an issue with box2d not installing properly. Thus, this
PR also moves swig installation before box2d so that swig is available
when box2d is being built. See
Farama-Foundation/Gymnasium#662 for more info

## TODO

- [ ] test code on linux machine

## Questions

<!-- Any concerns or points of confusion? -->

## Status

- [x] I have read the guidelines in
[CONTRIBUTING.md](https://github.com/icaros-usc/pyribs/blob/master/CONTRIBUTING.md)
- [x] I have formatted my code using `yapf`
- [x] I have tested my code by running `pytest`
- [x] I have linted my code with `pylint`
- [x] I have added a one-line description of my change to the changelog
in `HISTORY.md`
- [x] This PR is ready to go

---------

Co-authored-by: Bryon Tjanaka <bryon.tjanaka@gmail.com>
Co-authored-by: Bryon Tjanaka <38124174+btjanaka@users.noreply.github.com>
@btjanaka
Copy link
Contributor

Hi @pseudo-rnd-thoughts, I created #683 to resolve this issue. Let me know what you think!

@turbotimon
Copy link
Contributor

Hi @pseudo-rnd-thoughts can we improve the ImportError message to please? see my PR #1009

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants