Closed fehimornek closed 2 years ago
I have never seen this error before
Could you run pip uninstall gym
and pip install gym[box2d]
If this fail, could you give us the full install error message plus your operating system, the python version and the gym version that it tries to install.
Hey both, I encountered the same problem trying to create LunarLander
as well. It seems that the problem resides with Box2D and the related try
statement that leaves the problem undetected at https://github.com/openai/gym/blob/95063a08943e1f587c58be7435d94f81ccac8fd9/gym/envs/box2d/__init__.py#L1-L2
When I tried pip install gym[box2d]
, it also resulted in same problems: error: legacy-install-failure.
I got around the problem by installing Box2D manually with pip install box2d pygame
, and it works now.
@pseudo-rnd-thoughts: I noticed that gym's setup.py
uses a deprecated version of Box2D (box2d-py
). Perhaps the team would like to consider updating it to Box2D
instead? https://pypi.org/project/Box2D/
adding on: perhaps it would be useful to raise an error message when importing Box2D causes ImportErrors
to help with debugging.
@sidney-tio Thanks for the comment, I had never seen that try and except and will see if I can remove that
Investigating the box2d-py
install, this seems to be a legacy produce of gym where OpenAI forked an old repo of box2d as the install from pip
I will investigate moving to the more recent box2d as a temporary solution as we planning on moving to brax which should improve performance for the environments however this could be a few months out at
Hi again, I tried both of the solutions and they didn't work, here are the error messages:
1. solution
pip uninstall gym
pip install gym[box2d]
Collecting gym[box2d] Using cached gym-0.23.1-py3-none-any.whl Requirement already satisfied: numpy>=1.18.0 in c:\users\fehim\pycharmprojects\cybernetics\venv\lib\site-packages (from gym[box2d]) (1.22.2) Requirement already satisfied: cloudpickle>=1.2.0 in c:\users\fehim\pycharmprojects\cybernetics\venv\lib\site-packages (from gym[box2d]) (2.0.0) Requirement already satisfied: importlib-metadata>=4.10.0 in c:\users\fehim\pycharmprojects\cybernetics\venv\lib\site-packages (from gym[box2d]) (4.11.3) Requirement already satisfied: gym-notices>=0.0.4 in c:\users\fehim\pycharmprojects\cybernetics\venv\lib\site-packages (from gym[box2d]) (0.0.6) Collecting box2d-py==2.3.5 Using cached box2d-py-2.3.5.tar.gz (374 kB) Preparing metadata (setup.py) ... done Collecting pygame==2.1.0 Using cached pygame-2.1.0-cp39-cp39-win_amd64.whl (4.8 MB) Requirement already satisfied: zipp>=0.5 in c:\users\fehim\pycharmprojects\cybernetics\venv\lib\site-packages (from importlib-metadata>=4.10.0->gym[box2d]) (3.8.0) Building wheels for collected packages: box2d-py Building wheel for box2d-py (setup.py) ... error error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [16 lines of output] Using setuptools (version 57.0.0). running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.9 creating build\lib.win-amd64-3.9\Box2D copying library\Box2D\Box2D.py -> build\lib.win-amd64-3.9\Box2D copying library\Box2D__init.py -> build\lib.win-amd64-3.9\Box2D creating build\lib.win-amd64-3.9\Box2D\b2 copying library\Box2D\b2\init__.py -> build\lib.win-amd64-3.9\Box2D\b2 running build_ext building 'Box2D._Box2D' extension swigging Box2D\Box2D.i to Box2D\Box2D_wrap.cpp swig.exe -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 error: command 'swig.exe' failed: None [end of output]
note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for box2d-py Running setup.py clean for box2d-py Failed to build box2d-py Installing collected packages: box2d-py, pygame, gym Running setup.py install for box2d-py ... error error: subprocess-exited-with-error
× Running setup.py install for box2d-py did not run successfully. │ exit code: 1 ╰─> [16 lines of output] Using setuptools (version 57.0.0). running install running build running build_py creating build creating build\lib.win-amd64-3.9 [end of output]
note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure
× Encountered error while trying to install package. ╰─> box2d-py
note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.
2. solution
pip install gym[box2d] pygame
Collecting box2d Using cached Box2D-2.3.2.tar.gz (427 kB) Preparing metadata (setup.py) ... done Requirement already satisfied: pygame in c:\users\fehim\pycharmprojects\cybernetics\venv\lib\site-packages (2.1.2) Building wheels for collected packages: box2d Building wheel for box2d (setup.py) ... error error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [16 lines of output] Using setuptools (version 57.0.0). running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.9 creating build\lib.win-amd64-3.9\Box2D copying library\Box2D\Box2D.py -> build\lib.win-amd64-3.9\Box2D copying library\Box2D__init.py -> build\lib.win-amd64-3.9\Box2D creating build\lib.win-amd64-3.9\Box2D\b2 copying library\Box2D\b2\init__.py -> build\lib.win-amd64-3.9\Box2D\b2 running build_ext building 'Box2D._Box2D' extension swigging Box2D\Box2D.i to Box2D\Box2D_wrap.cpp swig.exe -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 error: command 'swig.exe' failed: None [end of output]
note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for box2d Running setup.py clean for box2d Failed to build box2d Installing collected packages: box2d Running setup.py install for box2d ... error error: subprocess-exited-with-error
× Running setup.py install for box2d did not run successfully. │ exit code: 1 ╰─> [16 lines of output] Using setuptools (version 57.0.0). running install running build running build_py creating build creating build\lib.win-amd64-3.9 creating build\lib.win-amd64-3.9\Box2D copying library\Box2D\Box2D.py -> build\lib.win-amd64-3.9\Box2D copying library\Box2D__init.py -> build\lib.win-amd64-3.9\Box2D creating build\lib.win-amd64-3.9\Box2D\b2 copying library\Box2D\b2\init__.py -> build\lib.win-amd64-3.9\Box2D\b2 running build_ext building 'Box2D._Box2D' extension swigging Box2D\Box2D.i to Box2D\Box2D_wrap.cpp swig.exe -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 error: command 'swig.exe' failed: None [end of output]
note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure
× Encountered error while trying to install package. ╰─> box2d
note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.
Sorry for the late reply
The error was caused by swig error: command 'swig.exe' failed: None
You can download swig here
This should fix your issue.
if install swig doesnt work, try installing box2d manually (i.e. pip install box2d
(instead of gym[box2d])? see my reply above:
Hey both, I encountered the same problem trying to create
LunarLander
as well. It seems that the problem resides with Box2D and the relatedtry
statement that leaves the problem undetected atWhen I tried
pip install gym[box2d]
, it also resulted in same problems: error: legacy-install-failure.I got around the problem by installing Box2D manually with
pip install box2d pygame
, and it works now.
After downloading swig I also had to
pip3 install box2d box2d-kengz
Solved the issue
But I don't understand why doing such a menial task required this many steps, what was the problem here me or the gym library?
So box2d
is different from box2d-py
that gym uses. You should just need to install swig
(which is a requirement of box2d) and then run pip install gym[box2d]
how am I supposed to install swig after downloading it ?
@Ashfaqe-oss In Ubuntu it should just be sudo apt install swig
, on MacOS it should be sudo brew install swig
, we don't have official Windows support.
Thanks. It works.
I've tried installing swig first:
sudo apt install swig
And only then install box2d:
pip install gymnasium
pip install gymnasium[box2d]
It succeeded without any error or warning.
When I uninstalled swig and reinstalled it I got
WARNING: The script swig.exe is installed in 'C:[...]\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Might this explain the (error: command 'swig.exe' failed: None) when installing gym[box2d] ?
@Louis1234567890, possibly, SWIG is a parser for Cpp to Python, so things could fail if that's not on PATH. That said, I've never developed code in Windows so I wouldn't know.
After downloading swig I also had to
pip3 install box2d box2d-kengz
Solved the issue
But I don't understand why doing such a menial task required this many steps, what was the problem here me or the gym library?
thank you, it helps me
After downloading swig I also had to
pip3 install box2d box2d-kengz
Solved the issue
But I don't understand why doing such a menial task required this many steps, what was the problem here me or the gym library?
Thanks, this helped me.
EveryOne, Instead of box2d install pip install pygame to get rid of this headache. Hope problem answered successfuly
Hey both, I encountered the same problem trying to create
LunarLander
as well. It seems that the problem resides with Box2D and the relatedtry
statement that leaves the problem undetected atWhen I tried
pip install gym[box2d]
, it also resulted in same problems: error: legacy-install-failure.I got around the problem by installing Box2D manually with
pip install box2d pygame
, and it works now.@pseudo-rnd-thoughts: I noticed that gym's
setup.py
uses a deprecated version of Box2D (box2d-py
). Perhaps the team would like to consider updating it toBox2D
instead? https://pypi.org/project/Box2D/
Thank you immensely. Your solution was helpful and resolved my issue.
If you ended up here because of the following error: zsh: no matches found: gymnasium[box2d]
Try pip install 'gymnasium[box2d]'
Basically, Z shell interprets the square brackets as a pattern matching expression, and searches for files named "b" or "o" or "x" and so on. Enclosing it with quotations (' ') makes Zsh treat everything inside as a single string without any special characters.
If you ended up here because of the following error:
zsh: no matches found: gymnasium[box2d]
Trypip install 'gymnasium[box2d]'
Basically, Z shell interprets the square brackets as a pattern matching expression, and searches for files named "b" or "o" or "x" and so on. Enclosing it with quotations (' ') makes Zsh treat everything inside as a single string without any special characters.
This solved my problem
If you ended up here because of the following error:
zsh: no matches found: gymnasium[box2d]
Trypip install 'gymnasium[box2d]'
Basically, Z shell interprets the square brackets as a pattern matching expression, and searches for files named "b" or "o" or "x" and so on. Enclosing it with quotations (' ') makes Zsh treat everything inside as a single string without any special characters.
I could kiss you
I am having trouble in a very simple task. I am trying to run CarRacing environment with the following code
and it throws an error AttributeError: module 'gym.envs.box2d' has no attribute 'CarRacing' I tried to run another code that was proposed in another issue #2786 like this
but this time got the error ModuleNotFoundError: No module named 'Box2D'
When I try to download Box2D with
it says error: legacy-install-failure
and I searched online but solutions for gym doesnt really exist.
Thanks in advance.