Problems pip installing Box2D
Solution 1
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
Solution 2
Mac users should try:
brew install swig
pip install box2d-py
pip install box2d
terminates without errors under macOS Mojave (10.14)
Solution 3
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
.
Solution 4
For Ubuntu 18.04, the following solved my problem with gym and lunar lander :
pip3 install box2d-py
Related videos on Youtube
Oliver G
I'm currently self-learning some books on mathematics. Mathematical Background: Mathematical Proofs, Calculus I-IV, Linear Algebra, Differential Equations, Engineering Mathematics, Real Analysis, General Topology, number theory, complex analysis, signals and systems. Additional knowledge of: Physics, Circuit Analysis, C++, Python
Updated on July 20, 2022Comments
-
Oliver G almost 2 years
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?
Edit:
When trying to pip install box2d-py I get this error:
-
Oliver G over 5 yearsWhen I try that I get another error (see edited question).
-
Oliver G over 5 yearsDoes the new error give you any idea what the problem is? I am still trying to get this to work.
-
Krishna over 5 yearsHi @OliverG , you found any solution? I'm also stuck on the same for a few days.
-
Oliver G over 5 years@krishna I have yet to find a solution.
-
Krishna over 5 yearsI 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 : stackoverflow.com/a/50719412/7699859 -
Oliver G over 5 yearsI am using windows. Do you know how to do this on windows or how to fix the error I posted?
-
Dima Fomin over 4 yearsI 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
:( -
BigBadMe over 4 yearsI'm not sure. I'm running Build Tools 2017 so if you're having problems then perhaps try that. It can be downloaded here: 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.
-
davidfrancis over 4 yearsGreat 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
-
Codeoneb almost 4 yearspip install gym==0.7.4 install this version of gym firsrt then just use this command
-
nosh almost 4 yearsWhat will
pip install Box2D
do? How will it fix the installation errors? Is it a suggested equivalent? -
Vijayabhaskar J over 3 yearsIt worked for me on WIN10, I don't know why you got downvoted.