18

I'm learning Reinforcement learning and I'm having the following errors.

Error(1) = I can't set up the 'CarRacing-v0' gym environment without Box2D

Error(2) = I can't pip install the Box2D module.

Does someone know how to interpret these errors and help me fix this?


enter image description here

enter image description here

Edit:

When trying to pip install box2d-py I get this error:

enter image description here

Oliver G
  • 375
  • 1
  • 3
  • 16

7 Answers7

13

Mac users should try:

  1. brew install swig
  2. pip install box2d-py
  3. pip install box2d

terminates without errors under macOS Mojave (10.14)

whiletrue
  • 10,500
  • 6
  • 27
  • 47
9

Windows users need to do as follows:

  • Download SWIG with the prebuilt executable and extract somewhere on your PC. Please note: I don't think SWIG 4.0 is compatible with Box2D yet, at time of writing SWIG 3.0.12 must be used.
  • Add the SWIG directory containing swig.exe to system PATH environment variable.
  • Install Microsoft Visual C++ 14.0. Get it with "Microsoft Visual C++ Build Tools".
  • pip install box2d
  • pip install box2d-py
BigBadMe
  • 1,754
  • 1
  • 19
  • 27
  • I wonder if it needs exactly MS VC++ 14.0? I've just installed MS VC Build Tools 2019, but swig do NOT see it during ```pip install box2d``` :( – Dima Fomin Sep 01 '19 at 17:22
  • 1
    I'm not sure. I'm running Build Tools 2017 so if you're having problems then perhaps try that. It can be downloaded here: https://visualstudio.microsoft.com/vs/older-downloads/ Also remember if you have amended your PATH variable then you need to start a new cmd prompt to pick up the changes. If you run swig.exe from a command prompt you should get a response back. – BigBadMe Sep 02 '19 at 10:31
  • 1
    Great post, thanks. Be careful to download the right tools from the Microsoft site - I had to open the group "Tools for Visual Studio 2019" and then click on "Build Tools for Visual Studio 2019". Then the option to install the Microsoft Visual C++ Build Tools is shown during installation. It was a 1 GB approx download – davidfrancis Sep 28 '19 at 23:44
2

For Ubuntu 20.04.3, I had to run the following:

sudo apt-get install swig build-essential python-dev python3-dev

before installing box2d-py.

Paul Ngo
  • 99
  • 1
  • 8
1

Based on gym's setup.py, it appears that the Box2D it is trying to import comes from the optional dependency box2d-py, so you need to run pip install box2d-py.

jwodder
  • 54,758
  • 12
  • 108
  • 124
  • When I try that I get another error (see edited question). – Oliver G Aug 12 '18 at 17:50
  • Does the new error give you any idea what the problem is? I am still trying to get this to work. – Oliver G Aug 24 '18 at 21:37
  • 1
    Hi @OliverG , you found any solution? I'm also stuck on the same for a few days. – Krishna Sep 12 '18 at 10:26
  • @krishna I have yet to find a solution. – Oliver G Sep 12 '18 at 22:09
  • 1
    I got past that solution but there is another error again. I used ```!apt-get update !apt-get install golang libcupti-dev libjpeg-turbo8-dev make tmux htop chromium-browser git cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig !pip install Box2D !apt-get install python-box2d !pip install box2d-py ``` You can try this answer as well : https://stackoverflow.com/a/50719412/7699859 – Krishna Sep 13 '18 at 04:42
1

For Ubuntu 18.04, the following solved my problem with gym and lunar lander :

pip3 install box2d-py
0

I know this does not solve the problem but after trying for an entire day I ended up running the game using Google Colab Notebooks. Only problem with that is it's a bit hard to render the screen but there is a post on the topic here.

-3

pip install Box2D

it will work 100%