Install pybox2d for python 3.6 with conda 4.3.21
Asked Answered
S

5

15

i want to play with the lunar lander env from OpenAI gym.

In order to run this code I need to install Box2d, this is where my problems arise. I am using ubuntu 16.04 with conda 4.3.21 and python 3.6. When I tried to run the environment I received the error: ModuleNotFoundError: No module named '_Box2D'

So I tried the direct install of pybox2d: https://github.com/pybox2d/pybox2d/blob/master/INSTALL.md which yielded the same error message.

Then I tried to install from GitHub following the way outlined in https://github.com/cbfinn/gps/issues/34

$git clone https://github.com/pybox2d/pybox2d pybox2d_dev
$cd pybox2d_dev
$python setup.py build 
$sudo python setup.py install

If I run this (in root environment which has python 3 or another new created environment with python 3) i get the result:

a lot of processing logs Processing Box2D-2.3.2-py2.7-linux-x86_64.egg creating /usr/local/lib/python2.7/dist-packages/Box2D-2.3.2-py2.7-linux-x86_64.egg Extracting Box2D-2.3.2-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages Adding Box2D 2.3.2 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/Box2D-2.3.2-py2.7-linux-x86_64.egg Processing dependencies for Box2D==2.3.2 Finished processing dependencies for Box2D==2.3.2

So pybox2d is installed into the lib of the standard python 2 of ubuntu despite being in a python 3 conda environment.

So, I am looking for ways to install the pybox2d package for python 3 with conda 4.3.21

Substantiate answered 26/5, 2017 at 9:35 Comment(0)
I
35

Installing Box2D from pip led me to the error described here when I tried to import it. Here's what worked for me on Python 3.6, as suggested in that GitHub issue:

conda install swig # needed to build Box2D in the pip install
pip install box2d-py # a repackaged version of pybox2d
Inconclusive answered 24/1, 2019 at 2:56 Comment(1)
box2d-py gym[box2d] also satisfies. swig doesn't look like a must-install package.Shaunna
E
9

Hey this question looks quite old but it seems no one really put the right answer in any where so just write this.

Follow the below two lines on your linux command:

$ sudo apt-get install build-essential python-dev swig python-pygame

$ pip install Box2D

---------Below is unnecessary details --------

Many wants to run Box2D based gym but it is sth you have to install by yourself like Mujoco series gym envs.

Many uses python 3.6 but the easiest way of installing Box2D, which is $ conda install -c kne pybox2d doesn't work cuz pybox2d has been maintained til py3.5

But directly doing $ pip install Box2D does not solve the issue. The error comes from swig given its error msg, but it's actually not. $ sudo apt-get install build-essential python-dev swig python-pygame This line always solve everything in one go.

I have been doing research based on Box2D envs but still foget this everytime I install this in a new env, so this is for me as well lol

Contribute: https://github.com/jonasschneider/box2d-py/blob/master/INSTALL.md

Btw, do not forget to double-check whether it is properly install. In linux command

$ python --version
python 3.6. sthsth
$ python
>>> import numpy as np
>>> import gym
>>> env = gym.make('BipedalWalker-v2')
# If it does not give you error, then it's done!
Earn answered 30/6, 2018 at 6:33 Comment(5)
Btw, do not forget to double-check whether it is properly install.Earn
It did not give me an error, but a warning: WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype.Babarababassu
How do I install the same things using windows?Drupe
@Drupe the best answer would be to run ubuntu os on windows in these days. Do not try to setup your default dev environments primarily on windows unless you are comfortable on what you have been doing. Try WSL2. This will give you Ubuntu OS screen-session on your window.Earn
@HermesMorales it is a warning not relevant to the gym itself, but sometimes it requires you to specify some data types of related modules like numpy. As is not specified by you, gym chooses a reasonable type as np.float32 out of np.float64, and etc. You may not need to worry about that for this case at this moment.Earn
K
0

You need to activate your environment:

source activate my_env_name

Then prompt changes to:

(my_env_name)

Now, install with pip and without sudo:

pip install pybox2d
Klepht answered 25/6, 2017 at 20:43 Comment(0)
I
0
sudo apt-get install swig

pip install pybox2d
Irita answered 7/6, 2021 at 5:15 Comment(1)
package name does not existCoreligionist
B
0

Installing this way worked for me (also in a virtual env):

pip install box2d-py==2.3.8

I am running gym v 0.17.3.

Beethoven answered 30/12, 2021 at 16:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.