Repository: openai/gym

Issue:
Box2d won't find some RAND_LIMIT_swigconstant
Hello!

It's probably some silly mistake on my side, but i wasn't able to fix by random lever pulling, as usual.

Installing Box2d as in instuctions (using `pip install -e .[all]`) will throw error when trying to use some of Box2D examples.

Code that reproduces the issue:

```
import gym
atari = gym.make('LunarLander-v0')
atari.reset()
```

```
[2016-05-16 02:14:25,430] Making new env: LunarLander-v0

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-f89e78f4410b> in <module>()
      1 import gym
----> 2 atari = gym.make('LunarLander-v0')
      3 atari.reset()
      4 #plt.imshow(atari.render('rgb_array'))

/home/jheuristic/yozhik/gym/gym/envs/registration.pyc in make(self, id)
     77         logger.info('Making new env: %s', id)
     78         spec = self.spec(id)
---> 79         return spec.make()
     80 
     81     def all(self):

/home/jheuristic/yozhik/gym/gym/envs/registration.pyc in make(self)
     52             raise error.Error('Attempting to make deprecated env {}. (HINT: is there a newer registered version of this env?)'.format(self.id))
     53 
---> 54         cls = load(self._entry_point)
     55         env = cls(**self._kwargs)
     56 

/home/jheuristic/yozhik/gym/gym/envs/registration.pyc in load(name)
     11 def load(name):
     12     entry_point = pkg_resources.EntryPoint.parse('x={}'.format(name))
---> 13     result = entry_point.load(False)
     14     return result
     15 

/home/jheuristic/thenv/local/lib/python2.7/site-packages/pkg_resources/__init__.pyc in load(self, require, *args, **kwargs)
   2378         if require:
   2379             self.require(*args, **kwargs)
-> 2380         return self.resolve()
   2381 
   2382     def resolve(self):

/home/jheuristic/thenv/local/lib/python2.7/site-packages/pkg_resources/__init__.pyc in resolve(self)
   2384         Resolve the entry point from its module and attrs.
   2385         """
-> 2386         module = __import__(self.module_name, fromlist=['__name__'], level=0)
   2387         try:
   2388             return functools.reduce(getattr, self.attrs, module)

/home/jheuristic/yozhik/gym/gym/envs/box2d/__init__.py in <module>()
----> 1 from gym.envs.box2d.lunar_lander import LunarLander
      2 from gym.envs.box2d.bipedal_walker import BipedalWalker, BipedalWalkerHardcore

/home/jheuristic/yozhik/gym/gym/envs/box2d/lunar_lander.py in <module>()
      3 from six.moves import xrange
      4 
----> 5 import Box2D
      6 from Box2D.b2 import (edgeShape, circleShape, fixtureDef, polygonShape, revoluteJointDef, contactListener)
      7 

/home/jheuristic/thenv/local/lib/python2.7/site-packages/Box2D/__init__.py in <module>()
     18 # 3. This notice may not be removed or altered from any source distribution.
     19 #
---> 20 from .Box2D import *
     21 __author__ = '$Date$'
     22 __version__ = '2.3.1'

/home/jheuristic/thenv/local/lib/python2.7/site-packages/Box2D/Box2D.py in <module>()
    433     return _Box2D.b2CheckPolygon(shape, additional_checks)
    434 
--> 435 _Box2D.RAND_LIMIT_swigconstant(_Box2D)
    436 RAND_LIMIT = _Box2D.RAND_LIMIT
    437 

AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'

```

What didn't help:

```
pip uninstall gym
apt-get install -y python-numpy python-dev cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl
git clone https://github.com/openai/gym
cd gym
pip install -e .[all] --upgrade
```

The OS is Ubuntu 14.04 Server x64
It may be a clue that i am running the thing from inside python2 virtualenv (with all numpys, etc. installed)



Discussion:
Ah, sorry, you need to install a backported swig 3.0: https://github.com/openai/gym/blob/box2dtests/.travis.yml#L20-L22. @jonasschneider is going to add code soon to make this error more friendly. LMK if you have trouble.

Thanks for the response!

Ran both selected lines, but it still throws the same error message.

On another machine (ubuntu 12 x64 server), OpenAI gym wouldn't install without these lines, but after running them it started throwing these errors as well.

Hm, @jonasschneider any ideas?

Ah, sorry for not following up on this yet. This seems to be a really strange regression within SWIG -- taking a look at the failing source, the `swigconstant` thing is just a function that the generated code assumes to be present, but it's not being defined anywhere.

One of the only references to this issue that I could dig up is http://lists.alioth.debian.org/pipermail/pkg-exppsy-pymvpa/2015q3.txt (grep for `swigconstant`). For them, SWIG 3.0.6 is _failing_, while SWIG 3.0.2 is _working_.

@justheuristic Could you do a `swig -version` to see if we have a similar case here?
(Mid-term we should nuke SWIG altogether, really.)

I can confirm I'm having the same problem. @jonasschneider I initially had version `SWIG Version 2.0.11`, then I followed [@gdb comment](https://github.com/openai/gym/issues/83#issuecomment-218357232) and now I have version:

```
$ swig -version
SWIG Version 3.0.2
Compiled with g++ [x86_64-unknown-linux-gnu]
Configured options: +pcre
Please see http://www.swig.org for reporting bugs and further inform
```

Unfortunately, I'm still seeing `AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant`. Thanks

[pybox2d](https://github.com/pybox2d/pybox2d) builds from source in Linux and Mac just fine. SWIG is next to invisible, I have 3.0.8. I understand they were using deprecated SWIG features at a time they built pip package and it wasn't updated since then. The solution is to fix pip to fetch current sources, I believe.

I also noticed @jonasschneider posted https://github.com/pybox2d/pybox2d/issues/82 , on the first look it says the right thing (please update pypi package). I am not familiar with pip packaging system (pypi?) so maybe I got it wrong.

Thanks for the response @olegklimov 
- I've just ensured my pip is up-to-date with `sudo pip install --upgrade pip`,
- ensured my local gym repo is up-to-date GitHub/master,
- and installed swig3.0.8 from [sources at SourceForge](https://sourceforge.net/projects/swig/?source=typ_redirect), which required `sudo apt-get install libpcre3 libpcre3-dev`, (I also uninstalled swig3.0.2 that I installed [above](https://github.com/openai/gym/issues/100#issuecomment-219509046), so hopefully python should be using swig3.0.8), but unfortunately I'm still getting:

```
$ swig -version
SWIG Version 3.0.8
Compiled with g++ [x86_64-unknown-linux-gnu]
Configured options: +pcre
Please see http://www.swig.org for reporting bugs and further information

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gym
>>> env = gym.make("LunarLander-v1")
[2016-05-16 21:29:12,097] Making new env: LunarLander-v1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/git/gym/gym/envs/registration.py", line 79, in make
    return spec.make()
  File "~/git/gym/gym/envs/registration.py", line 54, in make
    cls = load(self._entry_point)
  File "~/git/gym/gym/envs/registration.py", line 13, in load
    result = entry_point.load(False)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "~/git/gym/gym/envs/box2d/__init__.py", line 1, in <module>
    from gym.envs.box2d.lunar_lander import LunarLander
  File "~/git/gym/gym/envs/box2d/lunar_lander.py", line 4, in <module>
    import Box2D
  File "/usr/local/lib/python2.7/dist-packages/Box2D/__init__.py", line 20, in <module>
    from .Box2D import *
  File "/usr/local/lib/python2.7/dist-packages/Box2D/Box2D.py", line 435, in <module>
    _Box2D.RAND_LIMIT_swigconstant(_Box2D)
AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'
```

@asmith26 did you compile pybox2d yourself? From a fresh git clone? 

swig is used while compiling the native code of Box2D, so after updating
swig you need re-install Box2D with

```
    cd Box2D-py
    python setup.py clean
    python setup.py install
```

On Mon, May 16, 2016 at 1:38 PM, asmith26 notifications@github.com wrote:

> Thanks for the response @olegklimov https://github.com/olegklimov
> - I've just ensured my pip is up-to-date with sudo pip install
>   --upgrade pip,
> - ensured my local gym repo is up-to-date GitHub/master,
> - and installed swig3.0.8 from sources at SourceForge
>   https://sourceforge.net/projects/swig/?source=typ_redirect, which
>   required sudo apt-get install libpcre3 libpcre3-dev, (I also
>   uninstalled swig3.0.2 that I installed above
>   https://github.com/openai/gym/issues/100#issuecomment-219509046, so
>   hopefully python should be using swig3.0.8), but unfortunately I've still
>   getting:
> 
> $ swig -version
> SWIG Version 3.0.8
> Compiled with g++ [x86_64-unknown-linux-gnu]
> Configured options: +pcre
> Please see http://www.swig.org for reporting bugs and further information
> 
> $ python
> Python 2.7.6 (default, Jun 22 2015, 17:58:13)
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> 
> > > > import gym
> > > > env = gym.make("LunarLander-v1")
> > > > [2016-05-16 21:29:12,097] Making new env: LunarLander-v1
> > > > Traceback (most recent call last):
> > > >   File "<stdin>", line 1, in <module>
> > > >   File "~/git/gym/gym/envs/registration.py", line 79, in make
> > > >     return spec.make()
> > > >   File "~/git/gym/gym/envs/registration.py", line 54, in make
> > > >     cls = load(self._entry_point)
> > > >   File "~/git/gym/gym/envs/registration.py", line 13, in load
> > > >     result = entry_point.load(False)
> > > >   File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2229, in load
> > > >     return self.resolve()
> > > >   File "/usr/local/lib/python2.7/dist-packages/pkg_resources/**init**.py", line 2235, in resolve
> > > >     module = **import**(self.module_name, fromlist=['**name**'], level=0)
> > > >   File "~/git/gym/gym/envs/box2d/**init**.py", line 1, in <module>
> > > >     from gym.envs.box2d.lunar_lander import LunarLander
> > > >   File "~/git/gym/gym/envs/box2d/lunar_lander.py", line 4, in <module>
> > > >     import Box2D
> > > >   File "/usr/local/lib/python2.7/dist-packages/Box2D/**init**.py", line 20, in <module>
> > > >     from .Box2D import *
> > > >   File "/usr/local/lib/python2.7/dist-packages/Box2D/Box2D.py", line 435, in <module>
> > > >     _Box2D.RAND_LIMIT_swigconstant(_Box2D)
> > > > AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub
> https://github.com/openai/gym/issues/100#issuecomment-219540453

## 

Trevor Blackwell   tlb@openai.com    650 776 7870

Many thanks @tlbtlbtlb - worked perfectly!!

Got it running with @tlbtlbtlb 's tip,  sorry for the delay.
Thank you!

p.s. Anyone still has issues or this one can be closed?

Still failing for me. 

SWIG Version 3.0.8 (built from source)
$ swig -version
SWIG Version 3.0.8
Compiled with g++ [x86_64-unknown-linux-gnu]

$ git clone https://github.com/openai/gym
$ cd gym
$ pip install -e .
$ pip install -e .[Box2D]

PoleCart runs fine

$ cat a.py 
import gym
env = gym.make('LunarLander-v1')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action

$ python a.py
[2016-05-22 12:32:27,153] Making new env: LunarLander-v1
Traceback (most recent call last):
  File "a.py", line 2, in <module>
    env = gym.make('LunarLander-v1')
  File "/home/mike/gym/gym/envs/registration.py", line 84, in make
    return spec.make()
  File "/home/mike/gym/gym/envs/registration.py", line 56, in make
    cls = load(self._entry_point)
  File "/home/mike/gym/gym/envs/registration.py", line 14, in load
    result = entry_point.load(False)
  File "/home/mike/anaconda2/lib/python2.7/site-packages/setuptools-18.4 py2.7.egg/pkg_resources/__init__.py", line 2355, in load
  File "/home/mike/anaconda2/lib/python2.7/site-packages/setuptools-18.4-py2.7.egg/pkg_resources/**init**.py", line 2361, in resolve
  File "/home/mike/gym/gym/envs/box2d/**init**.py", line 1, in <module>
    from gym.envs.box2d.lunar_lander import LunarLander
  File "/home/mike/gym/gym/envs/box2d/lunar_lander.py", line 4, in <module>
    import Box2D
  File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/**init**.py", line 20, in <module>
    from .Box2D import *
  File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/Box2D.py", line 435, in <module>
    _Box2D.RAND_LIMIT_swigconstant(_Box2D)
AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'

no clue what's wrong...
  mike

@TheBlueFrog - I don't think your `pip install -e` command re-installs a package. I decided to remove the package and then install again with:

```
sudo pip uninstall box2d-py #EDITED 'pybox2d' -> 'box2d-py'
sudo pip install box2d-py     #EDITED 'pybox2d' -> 'box2d-py'
```

I do seem to have gotten past the swig issue

$ sudo pip uninstall pybox2d
Cannot uninstall requirement pybox2d, not installed
Storing debug log for failure in /home/mike/.pip/pip.log

$ sudo pip install pybox2d
Downloading/unpacking pybox2d
  Could not find any downloads that satisfy the requirement pybox2d
Cleaning up...
No distributions at all found for pybox2d
Storing debug log for failure in /home/mike/.pip/pip.log

$ cat /home/mike/.pip/pip.log
/usr/bin/pip run on Sun May 22 14:14:56 2016
Downloading/unpacking pybox2d
  Getting page https://pypi.python.org/simple/pybox2d/
  Could not fetch URL https://pypi.python.org/simple/pybox2d/: 404 Client Error: Not Found
  Will skip URL https://pypi.python.org/simple/pybox2d/ when looking for download links for pybox2d
  Getting page https://pypi.python.org/simple/
  URLs to search for versions for pybox2d:
   https://pypi.python.org/simple/pybox2d/
  Getting page https://pypi.python.org/simple/pybox2d/
  Could not fetch URL https://pypi.python.org/simple/pybox2d/: 404 Client Error: Not Found
  Will skip URL https://pypi.python.org/simple/pybox2d/ when looking for download links for pybox2d
  Could not find any downloads that satisfy the requirement pybox2d
Cleaning up...
  Removing temporary dir /tmp/pip_build_root...
No distributions at all found for pybox2d
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1178, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 277, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for pybox2d

There is something broken in Box2D for sure...

Try:

```
sudo pip uninstall box2d-py
sudo pip install box2d-py
```

weirder
installing box2d as root gives me a ImportError: No module named Box2D
installing as user gives me AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'

I note warnings when installing box2d as root that I don't get when
installing as user...

I'm getting the sense that there are two different box2d's around but
I don't know enough about pip to track it down...

$ pwd
/home/mike/gym
$ ls -l /usr/bin/sw*
lrwxrwxrwx 1 root root      16 May 22 12:04 /usr/bin/swig -> /usr/bin/swig3.0
-rwxr-xr-x 1 root root 1507832 May 19  2015 /usr/bin/swig3.0
$ swig -version
SWIG Version 3.0.8

$ pip uninstall box2d-py
Cannot uninstall requirement box2d-py, not installed
$ sudo pip uninstall box2d-py
Cannot uninstall requirement box2d-py, not installed
Storing debug log for failure in /home/mike/.pip/pip.log

$ sudo pip install box2d-py
Downloading/unpacking box2d-py
  Downloading box2d-py-2.3.1.tar.gz (425kB): 425kB downloaded
  Running setup.py (path:/tmp/pip_build_root/box2d-py/setup.py) egg_info for package box2d-py
    Using setuptools (version 3.3).
    warning: no files found matching 'INSTALL'
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'README'
    warning: no files found matching 'distribute_setup.py'
    warning: no files found matching '_.py' under directory 'Box2D'
    warning: no files found matching '_.c' under directory 'Box2D'
Installing collected packages: box2d-py
  Running setup.py install for box2d-py
    Using setuptools (version 3.3).
    building 'Box2D._Box2D' extension
    swigging Box2D/Box2D.i to Box2D/Box2D_wrap.cpp
    swig -python -c++ -IBox2D -small -O -includeall -ignoremissing -w201 -globals b2Globals -outdir library/Box2D -keyword -w511 -D_SWIG_KWARGS -o Box2D/Box2D_wrap.cpp Box2D/Box2D.i
    Box2D/Common/b2Math.h:67: Warning 302: Identifier 'b2Vec2' redefined by %extend (ignored),
    Box2D/Box2D_math.i:47: Warning 302: %extend definition of 'b2Vec2'.
///////////////// stuff deleted here ////////////////
    warning: no files found matching 'INSTALL'
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'README'
    warning: no files found matching 'distribute_setup.py'
    warning: no files found matching '_.py' under directory 'Box2D'
    warning: no files found matching '_.c' under directory 'Box2D'
Successfully installed box2d-py
Cleaning up...

$ cat b.py
import gym
env = gym.make('LunarLander-v1')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action

$ python b.py
[2016-05-23 10:12:29,394] Making new env: LunarLander-v1
Traceback (most recent call last):
  File "b.py", line 2, in <module>
    env = gym.make('LunarLander-v1')
  File "/home/mike/gym/gym/envs/registration.py", line 84, in make
    return spec.make()
  File "/home/mike/gym/gym/envs/registration.py", line 56, in make
    cls = load(self._entry_point)
  File "/home/mike/gym/gym/envs/registration.py", line 14, in load
    result = entry_point.load(False)
  File "/home/mike/anaconda2/lib/python2.7/site-packages/setuptools-18.4-py2.7.egg/pkg_resources/__init__.py", line 2355, in load
  File "/home/mike/anaconda2/lib/python2.7/site-packages/setuptools-18.4-py2.7.egg/pkg_resources/**init**.py", line 2361, in resolve
  File "/home/mike/gym/gym/envs/box2d/**init**.py", line 1, in <module>
    from gym.envs.box2d.lunar_lander import LunarLander
  File "/home/mike/gym/gym/envs/box2d/lunar_lander.py", line 4, in <module>
    import Box2D
ImportError: No module named Box2D

// ///////////////////// try installing as user /////////////////////////////////

$ sudo pip uninstall box2d-py
Uninstalling box2d-py:
  /usr/local/lib/python2.7/dist-packages/Box2D/Box2D.py
  /usr/local/lib/python2.7/dist-packages/Box2D/Box2D.pyc
  /usr/local/lib/python2.7/dist-packages/Box2D/_Box2D.so
  /usr/local/lib/python2.7/dist-packages/Box2D/__init__.py
  /usr/local/lib/python2.7/dist-packages/Box2D/**init**.pyc
  /usr/local/lib/python2.7/dist-packages/Box2D/b2/**init**.py
  /usr/local/lib/python2.7/dist-packages/Box2D/b2/**init**.pyc
  /usr/local/lib/python2.7/dist-packages/box2d_py-2.3.1.egg-info
Proceed (y/n)? y
  Successfully uninstalled box2d-py
$ pip uninstall box2d-py
Cannot uninstall requirement box2d-py, not installed
$ pip install box2d-py
Collecting box2d-py
Installing collected packages: box2d-py
Successfully installed box2d-py-2.3.1

$ python b.py
[2016-05-23 10:14:41,000] Making new env: LunarLander-v1
Traceback (most recent call last):
  File "b.py", line 2, in <module>
    env = gym.make('LunarLander-v1')
  File "/home/mike/gym/gym/envs/registration.py", line 84, in make
    return spec.make()
  File "/home/mike/gym/gym/envs/registration.py", line 56, in make
    cls = load(self._entry_point)
  File "/home/mike/gym/gym/envs/registration.py", line 14, in load
    result = entry_point.load(False)
  File "/home/mike/anaconda2/lib/python2.7/site-packages/setuptools-18.4-py2.7.egg/pkg_resources/__init__.py", line 2355, in load
  File "/home/mike/anaconda2/lib/python2.7/site-packages/setuptools-18.4-py2.7.egg/pkg_resources/**init**.py", line 2361, in resolve
  File "/home/mike/gym/gym/envs/box2d/**init**.py", line 1, in <module>
    from gym.envs.box2d.lunar_lander import LunarLander
  File "/home/mike/gym/gym/envs/box2d/lunar_lander.py", line 4, in <module>
    import Box2D
  File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/**init**.py", line 20, in <module>
    from .Box2D import *
  File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/Box2D.py", line 435, in <module>
    _Box2D.RAND_LIMIT_swigconstant(_Box2D)
AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'
$ 

ah, when boxd is installed as root I note this
File "/home/mike/gym/gym/envs/box2d/init.py", line 1, in 

but when installed as user 
File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/init.py", line 20, in 
from .Box2D import *

Encountered this same issue. Ultimately appears to have resolved thanks to @tlbtlbtlb's tip.

I had to install Box2D from source, though; the pip install did not work. 

@TheBlueFrog any updates here? Are you stuck at the same point with Box2D?

Same here. SWIG Version 3.0.10. Tried removing and reinstalling gym and box2d-py to no meaningful result.

**Update:** I managed to get it work by removing the Box2D installed with the gym and installing the new one from the git repository. It's important to remove all Box2D files before installation, because 'setup.py clean' doesn't do it.

In a similar vain to @Ivanopolo I uninstalled my pip installation of box2d-py via `sudo pip uninstall box2d-py` then built from source following instructions found [here](https://github.com/pybox2d/pybox2d/blob/master/INSTALL.md).

On OSX, I was able to resolve the issue by following the instructions posted by @bram1et and @Ivanopolo.

I'd like to share my experience for those who are still having this issue.

On Ubuntu 14.04, I tried using swig 3.0.2 and 3.0.10 built from the source, but none of them worked.
But manually (re)installing pybox2d from scratch by cloning the git repository, after enabling swig 3.0.8 built from the source, solved my problem.

I had the same issue, and after following the instruction suggested above, i.e. pip uninstall box2d-py and then build from source for Box2D. 

It leads to a new error:

`ImportError: No module named 'Box2D.b2'`

I am using Python 3 under Ubuntu 16.04 LTS, and all commands are running within an Anaconda environment. I had both conda install swig (latest version 3.0.10) and apt-get install swig (latest version 3.0.8)

End-to-end, explicit steps for fixing this problem (at least for MacOSX), save u the hunt for instructions scattered here and there:

``` shell
brew install cmake boost boost-python sdl2 swig wget
git clone https://github.com/openai/gym.git
cd gym
pip install -e '.[all]'
```

Try to run a Lunar Lander env, it will break (unless they fix it):

``` python
import gym
env = gym.make('LunarLander-v2')
env.reset()
env.render()
```

If it fails, debug as follow (and repeat once more if it fails again, glorious python):

``` shell
pip3 uninstall Box2D box2d-py
git clone https://github.com/pybox2d/pybox2d
cd pybox2d/
python setup.py clean
python setup.py build
python setup.py install
```

Thanks a lot for the comment by @kengz 

Now problem resolved. In my case described above, it seems important to run `pip3 uninstall box2d-py` and `python setup.py clean`. 

I **solved this issue on my system** (Ubuntu 14.04 LTS) installing Swig 3 and Box2D directly from sources. 
To install Swig >= 3 you can try with:

```bash
sudo apt-get -y install -t trusty-backports swig3.0
sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
```

The procedure to install Box2D is the following:

```bash
git clone https://github.com/pybox2d/pybox2d
cd pybox2d
python setup.py build
sudo python setup.py install
```

Good luck


@mpatacchiola 
In sudo python setup.py install` , is the "`" symbol at the end of the word "install" a typo? (I'm relatively new to linux).

Sorry GitHub is reading it as some style formatting. It is the symbol that comes below the tilde ~ on the same key
I would like to thank everyone on this thread. After a lot of effort trying to get it to work, I finally managed to.
I'm using Ubuntu 14.04, anaconda env with Python 3.5. I would like to point out this :  

Adding to @kengz post, also do 
pip uninstall Box2D box2d-py

They were already hiding in my environment but pip3 for some reason would say no such packages  were installed but pip found and got rid of them. Proceed to download pybox and install as given in the instructions
 
@arsenious 

Yes it was a typo. I edited the message to fix it. Anyway I'm glad you solved...

@kengz  Thanks. You help me a lot. Resolved for mac.
what about forking the box2d project under openai/box2d and use that one in the setup?
I experienced the same error, running Python 3 and swig 3.0.12 the below worked for me (make sure the directory containing swig.exe is in your path). The setup.py build was the key step
```

cd pybox2d/ 
python setup.py clean
python setup.py build
python setup.py install
```
I am using Python 2.7 with virtualenv&virtualenvwrapper on macOS Sierra 10.12.3, encountering the same problem, I solve it by solutions provided above.

In case some newbies like me do not know how to get started and become frustrated, I write it in details here for reference:

```
cd /Users/bing/OpenAI/gym    # your gym directory
pip uninstall box2d-py
git clone https://github.com/pybox2d/pybox2d pybox2d_dev
cd pybox2d_dev
python setup.py build    # this will take 10-15 seconds
python setup.py develop
```
After building and installing successfully, do not remove the `pybox2d_dev` directory.
It's OK to go now:
```
cd /Users/bing/OpenAI/gym
python    # in the terminal, enter interactive python 2.7 interpreter
import gym
env = gym.make('LunarLander-v2')
env.reset()
for _ in range(500):
  env.render()
  env.step(env.action_space.sample())
  (hit enter twice)
```

Exciting, here we go!
<img width="815" alt="screen shot 2017-03-20 at 12 10 05 am" src="https://cloud.githubusercontent.com/assets/18745870/24082675/6e0f97e6-0d04-11e7-83eb-a6781316433a.png">


When I do
`git clone https://github.com/pybox2d/pybox2d
cd pybox2d/
python setup.py clean
python setup.py build
python setup.py install`

I get this error: `ModuleNotFoundError: No module named '_Box2D'`. More precisely:
```
Using TensorFlow backend.
/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/keras/legacy/interfaces.py:86: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(6, input_shape=(6,), kernel_initializer="lecun_uniform")`
  '` call to the Keras 2 API: ' + signature)
/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/keras/legacy/interfaces.py:86: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(100, kernel_initializer="lecun_uniform")`
  '` call to the Keras 2 API: ' + signature)
/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/keras/legacy/interfaces.py:86: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(50, kernel_initializer="lecun_uniform")`
  '` call to the Keras 2 API: ' + signature)
/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/keras/legacy/interfaces.py:86: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(27, kernel_initializer="lecun_uniform")`
  '` call to the Keras 2 API: ' + signature)
[2017-03-20 12:34:19,518] Making new env: CarRacing-v0
Traceback (most recent call last):
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/pybox2d_dev/library/Box2D/Box2D.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: /disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/pybox2d_dev/library/Box2D/_Box2D.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "CarRacing_newQlearning.py", line 356, in <module>
    Rewards, Times, CummulativeRewards, Weights = Q_learning(model, epochs = 1, stages = 100, gamma = 0.975, epsilon = 0.99, batchSize = 100, buffer = 3000, randSeed = 42, replay = None)
  File "CarRacing_newQlearning.py", line 192, in Q_learning
    env = gym.make('CarRacing-v0')
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/gym/envs/registration.py", line 161, in make
    return registry.make(id)
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/gym/envs/registration.py", line 119, in make
    env = spec.make()
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/gym/envs/registration.py", line 85, in make
    cls = load(self._entry_point)
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/gym/envs/registration.py", line 17, in load
    result = entry_point.load(False)
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2258, in load
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2264, in resolve
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/gym/envs/box2d/__init__.py", line 1, in <module>
    from gym.envs.box2d.lunar_lander import LunarLander
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/gym/envs/box2d/lunar_lander.py", line 4, in <module>
    import Box2D
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/pybox2d_dev/library/Box2D/__init__.py", line 20, in <module>
    from .Box2D import *
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/pybox2d_dev/library/Box2D/Box2D.py", line 21, in <module>
    _Box2D = swig_import_helper()
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/site-packages/pybox2d_dev/library/Box2D/Box2D.py", line 20, in swig_import_helper
    return importlib.import_module('_Box2D')
  File "/disk/scratch/s1686829/anaconda/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_Box2D'
```

Any ideas what might be wrong?
Hi, @Instassa, it seems that your computer has not installed the box2d module successfully as expected, I guess there might exist some problems in directory path or python version, I see you are using anaconda's environment. Did you uninstall the original box2d module coming along with gym module completely?
Hi @tarvos21, if you mean originally before this:
```
git clone https://github.com/pybox2d/pybox2d cd pybox2d/
python setup.py clean
python setup.py build
python setup.py install
```
then I think yes, as my error first looks like `AttributeError: module '_Box2D' has no attribute 'RAND_LIMIT_swigconstant'`.
But after I perform the above series of commands I get `ModuleNotFoundError: No module named '_Box2D'`.
If installing swig3.0 is not an option, here is a workaround.
From https://github.com/pybox2d/pybox2d/blob/master/INSTALL.md, install a pre-built conda package of pybox2d with `conda install -c https://conda.anaconda.org/kne pybox2d`.
Don't forget to first uninstall previous versions with `pip uninstall Box2D box2d-py`.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@
 extras = {
   'atari': ['atari_py>=0.0.21', 'Pillow', 'PyOpenGL'],
   'board_game' : ['pachi-py>=0.0.19'],
-  'box2d': ['box2d-py'],
+  'box2d': ['Box2D-kengz'],
   'classic_control': ['PyOpenGL'],
   'mujoco': ['mujoco_py>=0.4.3', 'imageio'],
   'parameter_tuning': ['keras', 'theano'],


Test patch: