how can i install gym[box2d] despite errors below?

Question:

when i try to install gym[box2d] i get following error:
i tried: pip install gym[box2d].
on anaconda prompt i installed swig and gym[box2d] but i code in python3.9 env and it still not working.(my text editor is pycharm)
gym is already installed.and

ERROR: Command errored out with exit status 1:
   command: 'C:UsershoomanAppDataLocalProgramsPythonPython39python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\hoom
an\AppData\Local\Temp\pip-install-_vo0km5i\box2d-py_aea38b0da25341cf93e6a6c9d4b9d296\setup.py'"'"'; __file__='"'"'C:\Users\hooman\AppData\Local\Temp\pi
p-install-_vo0km5i\box2d-py_aea38b0da25341cf93e6a6c9d4b9d296\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else
 io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exe
c'"'"'))' bdist_wheel -d 'C:UsershoomanAppDataLocalTemppip-wheel-va_dgazk'
       cwd: C:UsershoomanAppDataLocalTemppip-install-_vo0km5ibox2d-py_aea38b0da25341cf93e6a6c9d4b9d296
  Complete output (16 lines):
  Using setuptools (version 58.2.0).
  running bdist_wheel
  running build
  running build_py
  creating build
  creating buildlib.win-amd64-3.9
  creating buildlib.win-amd64-3.9Box2D
  copying libraryBox2DBox2D.py -> buildlib.win-amd64-3.9Box2D
  copying libraryBox2D__init__.py -> buildlib.win-amd64-3.9Box2D
  creating buildlib.win-amd64-3.9Box2Db2
  copying libraryBox2Db2__init__.py -> buildlib.win-amd64-3.9Box2Db2
  running build_ext
  building 'Box2D._Box2D' extension
  swigging Box2DBox2D.i to Box2DBox2D_wrap.cpp
  swig.exe -python -c++ -IBox2D -small -O -includeall -ignoremissing -w201 -globals b2Globals -outdir libraryBox2D -keyword -w511 -D_SWIG_KWARGS -o Box2DBox2D_wr
ap.cpp Box2DBox2D.i
  error: command 'swig.exe' failed: None
  ----------------------------------------
  ERROR: Failed building wheel for box2d-py
  Running setup.py clean for box2d-py
Failed to build box2d-py
Installing collected packages: box2d-py
    Running setup.py install for box2d-py ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:UsershoomanAppDataLocalProgramsPythonPython39python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ho
oman\AppData\Local\Temp\pip-install-_vo0km5i\box2d-py_aea38b0da25341cf93e6a6c9d4b9d296\setup.py'"'"'; __file__='"'"'C:\Users\hooman\AppData\Local\Temp\
pip-install-_vo0km5i\box2d-py_aea38b0da25341cf93e6a6c9d4b9d296\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) el
se io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'e
xec'"'"'))' install --record 'C:UsershoomanAppDataLocalTemppip-record-yz4t1mq0install-record.txt' --single-version-externally-managed --compile --install-he
aders 'C:UsershoomanAppDataLocalProgramsPythonPython39Includebox2d-py'
         cwd: C:UsershoomanAppDataLocalTemppip-install-_vo0km5ibox2d-py_aea38b0da25341cf93e6a6c9d4b9d296
    Complete output (16 lines):
    Using setuptools (version 58.2.0).
    running install
    running build
    running build_py
    creating build
    creating buildlib.win-amd64-3.9
    creating buildlib.win-amd64-3.9Box2D
    copying libraryBox2DBox2D.py -> buildlib.win-amd64-3.9Box2D
    copying libraryBox2D__init__.py -> buildlib.win-amd64-3.9Box2D
    creating buildlib.win-amd64-3.9Box2Db2
    copying libraryBox2Db2__init__.py -> buildlib.win-amd64-3.9Box2Db2
    running build_ext
    building 'Box2D._Box2D' extension
    swigging Box2DBox2D.i to Box2DBox2D_wrap.cpp
    swig.exe -python -c++ -IBox2D -small -O -includeall -ignoremissing -w201 -globals b2Globals -outdir libraryBox2D -keyword -w511 -D_SWIG_KWARGS -o Box2DBox2D_
wrap.cpp Box2DBox2D.i
    error: command 'swig.exe' failed: None
    ----------------------------------------
ERROR: Command errored out with exit status 1: 
Asked By: Amaranth

||

Answers:

according to Anaconda, you should use the following command

conda install -c conda-forge gym-box2d

but you can still just install gym and from gym.envs import box2d

Answered By: Feras Alfrih

I think you are using windows for using openai gym which is not officially supported. gym installation for windows is not stable. Linux and mac are officially supported. I recommended this video Installing OpenAI Gym (gym[all]) on Linux, Windows and Mac for installing in Linux. you can use wsl2 in windows which i tried and worked.

Also this doc gym 0.7.4 helped me to set up the display in using wsl2(alias linux server according to the docs ).

Individual installation like box2d did not work for me. Try to install all gym envs as said in the video(takes a lot of space but no other option)

Answered By: Thrinay0403

I think you may go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ and find pybox2d and download the version which match your python version and run pip install Box2D‑2.3.10‑cp38‑cp38‑win_amd64.whl (change your wheel name!)

Answered By: finko

For me, the solution was to download and install the latest stable version of Build Tools pour Visual Studio (2022 currently) and to select C++ package during the installation. Then the pip install gym[box2d] worked.

Answered By: Clément Perroud
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.