Install pybox2d for python 3.6 with conda 4.3.21

R. M picture R. M · May 26, 2017 · Viewed 16k times · Source

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

Answer

Nathan picture Nathan · Jan 24, 2019

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