Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install pybox2d for python 3.6 with conda 4.3.21

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

like image 875
R. M Avatar asked May 26 '17 09:05

R. M


2 Answers

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
like image 84
Nathan Avatar answered Oct 14 '22 23:10

Nathan


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!
like image 27
sdr2002 Avatar answered Oct 14 '22 23:10

sdr2002