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

AttributeError: module 'Box2D._Box2D' has no attribute 'RAND_LIMIT' #647

Closed
Jackiexiao opened this issue Jul 8, 2017 · 20 comments
Closed

Comments

@Jackiexiao
Copy link

I can't run the LunarLander-v2 env, error occurs

[2017-07-08 12:53:22,066] Making new env: LunarLander-v2
Traceback (most recent call last):
  File "gym_test_CartPole.py", line 3, in <module>
    env = gym.make('LunarLander-v2')
  File "/home/jackie/gym/gym/envs/registration.py", line 161, in make
    return registry.make(id)
  File "/home/jackie/gym/gym/envs/registration.py", line 119, in make
    env = spec.make()
  File "/home/jackie/gym/gym/envs/registration.py", line 85, in make
    cls = load(self._entry_point)
  File "/home/jackie/gym/gym/envs/registration.py", line 17, in load
    result = entry_point.load(False)
  File "/home/jackie/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2303, in load
    return self.resolve()
  File "/home/jackie/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2309, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/jackie/gym/gym/envs/box2d/__init__.py", line 1, in <module>
    from gym.envs.box2d.lunar_lander import LunarLander
  File "/home/jackie/gym/gym/envs/box2d/lunar_lander.py", line 4, in <module>
    import Box2D
  File "/home/jackie/anaconda3/lib/python3.6/site-packages/Box2D/__init__.py", line 20, in <module>
    from .Box2D import *
  File "/home/jackie/anaconda3/lib/python3.6/site-packages/Box2D/Box2D.py", line 434, in <module>
    RAND_LIMIT = _Box2D.RAND_LIMIT
AttributeError: module 'Box2D._Box2D' has no attribute 'RAND_LIMIT'
@onaclov2000
Copy link

This is a known issue, and there is information here:
#100

I'm not sure regarding an anaconda environment if those dependencies should already be setup right, but since you're having the error, perhaps the link above can help

@Jackiexiao
Copy link
Author

Jackiexiao commented Jul 18, 2017

As @indescribable say, try pip3 install box2d box2d-kengz

@onaclov2000 Thx!
I solve this problem by building from source following instructions found here.

$ conda create -n py34 python=3.4
$ source activate py34
$ conda install -c https://conda.anaconda.org/kne pybox2d

it works well

python    
import gym
env = gym.make('LunarLander-v2')
env.reset()
for _ in range(500):
  env.render()
  env.step(env.action_space.sample())

@nbgraham
Copy link

nbgraham commented Oct 28, 2017

I am trying to use TensorFlow with my GPU on the CarRacing environment. This is really frustrating because TensorFlow with GPU only supports python 3.5.* and 3.6.* on Windows.
It seems that Box2D doesn't work with those, but only with 3.4.*

(py35_tf_gpu) C:\Users\nickb>conda install -c https://conda.anaconda.org/kne pybox2d
Fetching package metadata ...............
Solving package specifications: .

UnsatisfiableError: The following specifications were found to be in conflict:
  - pybox2d -> python 3.4*
  - python 3.5*
Use "conda info <package>" to see the dependencies for each package.

I tried with the newest swig (3.0.12) and 3.0.2, the one mentioned in #100 as working.

Neither one worked, giving the same error:

Traceback (most recent call last):
  File "C:/Users/nickb/PycharmProjects/RL-Race-Car-Simulator/run.py", line 157, in <module>
    main()
  File "C:/Users/nickb/PycharmProjects/RL-Race-Car-Simulator/run.py", line 21, in main
    run_simulator(continue_from, N, name)
  File "C:/Users/nickb/PycharmProjects/RL-Race-Car-Simulator/run.py", line 62, in run_simulator
    env = gym.make('CarRacing-v0')
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\gym\envs\registration.py", line 164, in make
    return registry.make(id)
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\gym\envs\registration.py", line 122, in make
    env = spec.make()
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\gym\envs\registration.py", line 88, in make
    cls = load(self._entry_point)
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\gym\envs\registration.py", line 17, in load
    result = entry_point.load(False)
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\pkg_resources\__init__.py", line 2409, in load
    return self.resolve()
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\pkg_resources\__init__.py", line 2415, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\gym\envs\box2d\__init__.py", line 1, in <module>
    from gym.envs.box2d.lunar_lander import LunarLander
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\gym\envs\box2d\lunar_lander.py", line 4, in <module>
    import Box2D
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\Box2D\__init__.py", line 20, in <module>
    from .Box2D import *
  File "C:\Users\nickb\Anaconda3\envs\py35_tf_gpu\lib\site-packages\Box2D\Box2D.py", line 435, in <module>
    _Box2D.RAND_LIMIT_swigconstant(_Box2D)
AttributeError: module '_Box2D' has no attribute 'RAND_LIMIT_swigconstant'

@vglazer
Copy link

vglazer commented Oct 29, 2017

@nbgraham, as far as I can tell the underlying SWIG regression, which is discussed in some detail here, was addressed in this patch.

However, it seems that when you pip install Box2D you pick up a package that was built before the issue was resolved.

One solution is to use box2d-py, as @Jackiexiao suggested above. I'm running Python 3.6, so I had to build box2d-py from source by following these instructions instead of installing the pre-built 3.4 package.

As long python setup.py build picks up a version of SWIG that doesn't have the swigconstant problem, you should be fine. On a Mac, brew install swig does the trick, but I verified that building SWIG 3.0.12 from source also works.

Hope this helps!

@nbgraham
Copy link

Installing pybox2d from source seemed to work. I have no idea what minGW and MSYS are, but I have Visual Studio installed, so maybe that's why it worked.

I got this error when trying to use the monitor

raise error.DependencyNotInstalled("""Found neither the ffmpeg nor avconv executables. On OS X, you can install ffmpeg via `brew install ffmpeg`. On most Ubuntu variants, `sudo apt-get install ffmpeg` should do it. On Ubuntu 14.04, however, you'll need to install avconv with `sudo apt-get install libav-tools`.""")
gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables. On OS X, you can install ffmpeg via `brew install ffmpeg`. On most Ubuntu variants, `sudo apt-get install ffmpeg` should do it. On Ubuntu 14.04, however, you'll need to install avconv with `sudo apt-get install libav-tools`.

It didn't give instructions on how to install ffmpeg on Windows. I found the ffmpeg download page, downloaded the zip, extracted it, and added the bin folder to my path and got it working.

Everything seems to be working, thanks!

@indescribable
Copy link

pip3 install box2d box2d-kengz

@qsheeeeen
Copy link

python3.5 ubuntu16
pip3 install gym[box2d]
pip3 install box2d
pip3 uninstall box2d-kengz

@xionghhcs
Copy link

xionghhcs commented Apr 9, 2018

come into the same problem.

My environment is conda,python=3.5.And I use

conda install -c https://conda.anaconda.org/kne pybox2d

finally it works.@Jackiexiao

@DuaneNielsen
Copy link

DuaneNielsen commented Jul 19, 2018

This is still broken. building gym from source using these instructions..

https://tzattackblog.wordpress.com/2018/01/08/attributeerror-module-_box2d-has-no-attribute-rand_limit_swigconstant/comment-page-1/#comment-4

  • installing

pip3 install box2d box2d-kengz

solved it for me, on mac OS

@NBJack
Copy link

NBJack commented Aug 21, 2018

Thanks for all the suggestions, but this is still broken for myself under Ubuntu 16.04 with Python 3.5.2.

This was marked as closed; what was done to resolve this fundamentally?

@Khev
Copy link

Khev commented Sep 7, 2018

I had the same problem. Doing the simple

  1. pip install --upgrade pip
  2. pip install Box2D

Worked for me. I'm running python 2.7, on ubuntu.

@DuaneNielsen
Copy link

@Khev what os were you running? I think OS matters here, as I understand it, mac/windows/linux all need different steps to solve ;)

@Khev
Copy link

Khev commented Sep 7, 2018

My bad -- have updated my comment :-)

@DuaneNielsen
Copy link

@Khev I realized my comment didnt have OS either :) Fixed it too!

@GoingMyWay
Copy link

GoingMyWay commented Mar 2, 2019

pip3 install box2d box2d-kengz

It helps on Ubuntu and Windows 10.

@awarebayes
Copy link

awarebayes commented Jul 4, 2019

conda install swig
pip install Box2D

TDS article with more details:
https://towardsdatascience.com/how-to-install-openai-gym-in-a-windows-environment-338969e24d30

@hai-h-nguyen
Copy link

python3.5 ubuntu16
pip3 install gym[box2d]
pip3 install box2d
pip3 uninstall box2d-kengz

Important here is the command pip3 install gym[box2d]. Only installing box2d and box2d-kengz does not solve the problem for me.

@VictoriaBentell
Copy link

pip install box2d-py worked for me on ubuntu 18.04 and python 3.7

@oslijunw
Copy link

oslijunw commented Apr 9, 2023

pip install box2d-py pygame worked for me on my mbp m1pro

@PrasannaMaddila
Copy link

pip install box2d-py pygame

Also worked for me on Fedora 38

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

No branches or pull requests