1、环境
windows、python 3.7、conda
2、安装gym
pip install gym[all]
报错:
Collecting pycparser
Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
---------------------------------------- 118.7/118.7 kB 315.3 kB/s eta 0:00:00
Building wheels for collected packages: Box2D-kengz
Building wheel for Box2D-kengz (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [28 lines of output]
Using setuptools (version 63.4.1).
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-37
creating build\lib.win-amd64-cpython-37\Box2D
copying library\Box2D\Box2D.py -> build\lib.win-amd64-cpython-37\Box2D
copying library\Box2D\__init__.py -> build\lib.win-amd64-cpython-37\Box2D
creating build\lib.win-amd64-cpython-37\Box2D\b2
copying library\Box2D\b2\__init__.py -> build\lib.win-amd64-cpython-37\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
Box2D\Common\b2Math.h(67) : Warning 302: Identifier 'b2Vec2' redefined by %extend (ignored),
Box2D\Box2D_math.i(47) : Warning 302: %extend definition of 'b2Vec2'.
Box2D\Common\b2Math.h(158) : Warning 302: Identifier 'b2Vec3' redefined by %extend (ignored),
Box2D\Box2D_math.i(168) : Warning 302: %extend definition of 'b2Vec3'.
Box2D\Common\b2Math.h(197) : Warning 302: Identifier 'b2Mat22' redefined by %extend (ignored),
Box2D\Box2D_math.i(301) : Warning 302: %extend definition of 'b2Mat22'.
Box2D\Common\b2Math.h(271) : Warning 302: Identifier 'b2Mat33' redefined by %extend (ignored),
Box2D\Box2D_math.i(372) : Warning 302: %extend definition of 'b2Mat33'.
Box2D\Collision\b2DynamicTree.h(44) : Warning 312: Nested union not currently supported (ignored).
Box2D\Common\b2Settings.h(144) : Warning 506: Can't wrap varargs with keyword arguments enabled
Box2D\Common\b2Math.h(91) : Warning 509: Overloaded method b2Vec2::operator ()(int32) effectively ignored,
Box2D\Common\b2Math.h(85) : Warning 509: as it is shadowed by b2Vec2::operator ()(int32) const.
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for Box2D-kengz
Running setup.py clean for Box2D-kengz
Failed to build Box2D-kengz
Installing collected packages: PyOpenGL, glfw, Box2D-kengz, pycparser, imageio, fasteners, Cython, atari-py, cffi, mujoco-py
Running setup.py install for Box2D-kengz ... error
error: subprocess-exited-with-error
× Running setup.py install for Box2D-kengz did not run successfully.
│ exit code: 1
╰─> [30 lines of output]
Using setuptools (version 63.4.1).
running install
D:\Program\anaconda3\envs\maddpg\lib\site-packages\setuptools\command\install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-37
creating build\lib.win-amd64-cpython-37\Box2D
copying library\Box2D\Box2D.py -> build\lib.win-amd64-cpython-37\Box2D
copying library\Box2D\__init__.py -> build\lib.win-amd64-cpython-37\Box2D
creating build\lib.win-amd64-cpython-37\Box2D\b2
copying library\Box2D\b2\__init__.py -> build\lib.win-amd64-cpython-37\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
Box2D\Common\b2Math.h(67) : Warning 302: Identifier 'b2Vec2' redefined by %extend (ignored),
Box2D\Box2D_math.i(47) : Warning 302: %extend definition of 'b2Vec2'.
Box2D\Common\b2Math.h(158) : Warning 302: Identifier 'b2Vec3' redefined by %extend (ignored),
Box2D\Box2D_math.i(168) : Warning 302: %extend definition of 'b2Vec3'.
Box2D\Common\b2Math.h(197) : Warning 302: Identifier 'b2Mat22' redefined by %extend (ignored),
Box2D\Box2D_math.i(301) : Warning 302: %extend definition of 'b2Mat22'.
Box2D\Common\b2Math.h(271) : Warning 302: Identifier 'b2Mat33' redefined by %extend (ignored),
Box2D\Box2D_math.i(372) : Warning 302: %extend definition of 'b2Mat33'.
Box2D\Collision\b2DynamicTree.h(44) : Warning 312: Nested union not currently supported (ignored).
Box2D\Common\b2Settings.h(144) : Warning 506: Can't wrap varargs with keyword arguments enabled
Box2D\Common\b2Math.h(91) : Warning 509: Overloaded method b2Vec2::operator ()(int32) effectively ignored,
Box2D\Common\b2Math.h(85) : Warning 509: as it is shadowed by b2Vec2::operator ()(int32) const.
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[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-kengz
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
3、安装SWIG
下载地址:
https://www.swig.org/download.html
下载后将压缩包解压,如解压至C:\Program Files\swigwin-4.0.0
随后设置环境变量:
我的电脑->属性->高级系统设置->环境变量->系统变量->双击PATH->新建。
随后输入C:\Program Files\swigwin-4.0.0
4、 安装Box2D
pip install box2d box2d-kengz
5、依旧报错
网上查找轮流尝试输入了以下命令
pip install box2d-py
pip install lockfile
(本人为python3.7,可输入python --version查看自身python版本,以下与语句可能根据python版本修改)
pip install https://download.lfd.uci.edu/pythonlibs/archived/cp37/Box2D-2.3.2-cp37-cp37m-win_amd64.whl
conda install -c anaconda swig
虽然输入上述命令有些还是报错,但是最后尝试运行代码,发现成功解决。。。
6、测试
python
>>>import numpy as np
>>>import gym
>>>env = gym.make('BipedalWalker-v2')
未报错即证明安装成功!!!!