Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box2d won't find some RAND_LIMIT_swigconstant #100

Closed
justheuristic opened this issue May 16, 2016 · 52 comments · Fixed by #558
Closed

Box2d won't find some RAND_LIMIT_swigconstant #100

justheuristic opened this issue May 16, 2016 · 52 comments · Fixed by #558
Assignees

Comments

@justheuristic
Copy link
Contributor

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)

@gdb
Copy link
Collaborator

gdb commented May 16, 2016

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.

@justheuristic
Copy link
Contributor Author

justheuristic commented May 16, 2016

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.

@gdb
Copy link
Collaborator

gdb commented May 16, 2016

Hm, @jonasschneider any ideas?

@jonasschneider
Copy link
Contributor

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.)

@jonasschneider jonasschneider self-assigned this May 16, 2016
@asmith26
Copy link
Contributor

asmith26 commented May 16, 2016

I can confirm I'm having the same problem. @jonasschneider I initially had version SWIG Version 2.0.11, then I followed @gdb comment 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

@olegklimov
Copy link
Contributor

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.

@olegklimov
Copy link
Contributor

I also noticed @jonasschneider posted pybox2d/pybox2d#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.

@asmith26
Copy link
Contributor

asmith26 commented May 16, 2016

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, which required sudo apt-get install libpcre3 libpcre3-dev, (I also uninstalled swig3.0.2 that I installed above, 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'

@olegklimov
Copy link
Contributor

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

@tlbtlbtlb
Copy link
Contributor

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 [email protected] wrote:

Thanks for the response @olegklimov https://github.com/olegklimov

$ 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 "", line 1, in
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
from gym.envs.box2d.lunar_lander import LunarLander
File "~/git/gym/gym/envs/box2d/lunar_lander.py", line 4, in
import Box2D
File "/usr/local/lib/python2.7/dist-packages/Box2D/init.py", line 20, in
from .Box2D import *
File "/usr/local/lib/python2.7/dist-packages/Box2D/Box2D.py", line 435, in
_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
#100 (comment)

Trevor Blackwell [email protected] 650 776 7870

@asmith26
Copy link
Contributor

Many thanks @tlbtlbtlb - worked perfectly!!

@justheuristic
Copy link
Contributor Author

justheuristic commented May 17, 2016

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?

@TheBlueFrog
Copy link

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
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
from gym.envs.box2d.lunar_lander import LunarLander
File "/home/mike/gym/gym/envs/box2d/lunar_lander.py", line 4, in
import Box2D
File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/init.py", line 20, in
from .Box2D import *
File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/Box2D.py", line 435, in
_Box2D.RAND_LIMIT_swigconstant(_Box2D)
AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'

no clue what's wrong...
mike

@asmith26
Copy link
Contributor

asmith26 commented May 22, 2016

@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'

@TheBlueFrog
Copy link

TheBlueFrog commented May 22, 2016

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...

@asmith26
Copy link
Contributor

Try:

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

@TheBlueFrog
Copy link

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
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
from gym.envs.box2d.lunar_lander import LunarLander
File "/home/mike/gym/gym/envs/box2d/lunar_lander.py", line 4, in
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
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
from gym.envs.box2d.lunar_lander import LunarLander
File "/home/mike/gym/gym/envs/box2d/lunar_lander.py", line 4, in
import Box2D
File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/init.py", line 20, in
from .Box2D import *
File "/home/mike/anaconda2/lib/python2.7/site-packages/Box2D/Box2D.py", line 435, in
_Box2D.RAND_LIMIT_swigconstant(_Box2D)
AttributeError: 'module' object has no attribute 'RAND_LIMIT_swigconstant'
$

@TheBlueFrog
Copy link

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 *

@jachiam
Copy link
Contributor

jachiam commented Jun 10, 2016

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.

@jietang
Copy link
Contributor

jietang commented Jun 13, 2016

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

@Ivanopolo
Copy link

Ivanopolo commented Jun 27, 2016

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.

@bram1et
Copy link

bram1et commented Jul 1, 2016

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.

@rdevon
Copy link

rdevon commented Sep 5, 2016

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

@jaekyeom
Copy link

jaekyeom commented Oct 1, 2016

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.

@zuoxingdong
Copy link
Contributor

zuoxingdong commented Nov 9, 2016

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)

@kengz
Copy link
Contributor

kengz commented Nov 12, 2016

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

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):

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):

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

@tarvos21
Copy link
Contributor

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?

@Instassa
Copy link

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'.

@garibarba
Copy link
Contributor

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.

@kengz
Copy link
Contributor

kengz commented Apr 11, 2017

This had to be fixed, so I did. The local installation works now. Submitted the PR above, hope the team reviews soon.

For those who can't wait, just install your gym from pip install -e git+https://github.com/kengz/gym.git#egg=gym[all]

@sdr2002
Copy link

sdr2002 commented Jul 3, 2017

Sorry but the issue is still not solved in clusters.
I have installed gym, Box2D via pip and for another chance I went with @kengz 's one, and both didn't work.
In local machines there are no problems but in the cluster(mine I have is Gridengine's) it is.
I got an error left below, so could you check this out? Thx.

----------------------------------------

Collecting PyOpenGL (from gym[all])
Using cached PyOpenGL-3.1.0.tar.gz
Collecting Box2D-kengz (from gym[all])
Using cached Box2D-kengz-2.3.3.tar.gz
Collecting keras (from gym[all])
Using cached Keras-2.0.5.tar.gz
Collecting theano (from gym[all])
Using cached Theano-0.9.0.tar.gz
Collecting atari_py>=0.0.21 (from gym[all])
Using cached atari-py-0.1.1.tar.gz
Collecting Pillow (from gym[all])
Using cached Pillow-4.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Collecting pachi-py>=0.0.19 (from gym[all])
Using cached pachi-py-0.0.21.tar.gz
Collecting mujoco_py>=0.4.3 (from gym[all])
Using cached mujoco-py-1.50.1.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-B8ZkMp/mujoco-py/setup.py", line 2, in
import importlib.util
ImportError: No module named util

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-B8ZkMp/mujoco-py/

"python setup.py egg_info" failed with error code 1 in /tmp/pip-build-B8ZkMp/mujoco-py/

@onaclov2000
Copy link

onaclov2000 commented Jul 31, 2017

nothing is working for me, I can't get my gym to uninstall due to this listed in freeze;

-e git+https://github.com/kengz/gym.git@b943b0ed2a00893f9eab37dcb13ca6f062005f12#egg=gym

EDIT went and removed the egg-link from /usr/local/python2.7/dist-packages

I still am unable to install anything and suspect everything is broken now.

@jrversteegh
Copy link

jrversteegh commented Aug 1, 2017

@kengz Your pull request appears to have been merged, but the issue still persists.
Latest master from github.com/openai/gym and pip install -e '.[all]'
AttributeError: module 'Box2D._Box2D' has no attribute 'RAND_LIMIT'

Removing with pip uninstall Box2D-kengz, then cloning github.com/pybox2d/pybox2d and doing a pip install -e . makes things work.

@mklissa
Copy link

mklissa commented Aug 7, 2017

@jrversteegh that worked for me! thanks

@LUKELIEM
Copy link

Just wondering, when will the Box2d issue be completely resolved in https://github.com/openai/gym so that we do not have to deal with all these workarounds?

@weiliu620
Copy link

@jrversteegh does not work for me.

@fedden
Copy link

fedden commented Oct 8, 2017

@jrversteegh that sorted it - thank you

@solomatov
Copy link

This issue is still reproducible:

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

I was using the LunarLander-v2 environment

@sprakashdash
Copy link

@solomatov When are you getting this error? Please put your code if my code doesnot solves the issue.
While I was running this:
import gym
atari = gym.make('LunarLander-v2')
atari.reset()
It showed me perfectly without any error:
array([ 0.00286407, 1.4008762 , 0.29008052, -0.44640478, -0.00331193, -0.06570757, 0. , 0. ], dtype=float32)

@kengz
Copy link
Contributor

kengz commented Jan 8, 2019

Seems like this is already fixed in the latest gym release using the proper box2d-py>=2.3.5 (the box2d-kengz hack had been replaced). I can confirm with plain pip install gym[box2d] on both MacOS and Linux Ubuntu, then checking with

import gym
gym.make('LunarLander-v2')

should pass without problem.

@eambutu
Copy link

eambutu commented Mar 30, 2019

For anyone still hitting this issue: you need to pip3 install box2d-py, and not pip3 install Box2d, as I mistakenly did.

@Taospirit
Copy link

@kengz Your pull request appears to have been merged, but the issue still persists.
Latest master from github.com/openai/gym and pip install -e '.[all]'
AttributeError: module 'Box2D._Box2D' has no attribute 'RAND_LIMIT'

Removing with pip uninstall Box2D-kengz, then cloning github.com/pybox2d/pybox2d and doing a pip install -e . makes things work.

thx, that worked for me!

tlpss added a commit to arjun-kg/rl-colab-notebooks that referenced this issue Oct 13, 2022
araffin added a commit to Stable-Baselines-Team/rl-colab-notebooks that referenced this issue Apr 14, 2023
* update to gym 0.23.1

* update HER

* check for gym v0.26 and add info on vecenv wrapping of new gym API

* check for gym v0.26 and update box2D installation
see openai/gym#100 (comment)

* update to gym v0.26 API

* update to gym v0.26

* Fixes and reformat

* Switch to Gymnasium

---------

Co-authored-by: tlpss <[email protected]>
Co-authored-by: Antonin Raffin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.