LunarLander 需要 Box2D,但是它的 pip 安装不起作用

问题描述

我一直在使用 PyCharm 学习一些强化学习,并且我在健身房 LunarLanding 环境中学习了使用 deep q 的教程,(https://www.youtube.com/watch?v=wc-FxNENg9U&t=1428s),

这是 python 文件创建的 GitHub 链接 (https://github.com/philtabor/Youtube-Code-Repository/blob/master/ReinforcementLearning/DeepQLearning/main_torch_dqn_lunar_lander_2020.py)

我目前在运行时遇到此错误

Traceback (most recent call last):
  File "C:\Users\Brian\Desktop\SURP\Pycharm\week_3_deep_q_lunar_landing\lunar_landing.py",line 7,in <module>
    env = gym.make("LunarLander-v2")
  File "C:\Users\Brian\Desktop\SURP\Pycharm\week_3_deep_q_lunar_landing\venv\lib\site-packages\gym\envs\registration.py",line 145,in make
    return registry.make(id,**kwargs)
  File "C:\Users\Brian\Desktop\SURP\Pycharm\week_3_deep_q_lunar_landing\venv\lib\site-packages\gym\envs\registration.py",line 90,in make
    env = spec.make(**kwargs)
  File "C:\Users\Brian\Desktop\SURP\Pycharm\week_3_deep_q_lunar_landing\venv\lib\site-packages\gym\envs\registration.py",line 59,in make
    cls = load(self.entry_point)
  File "C:\Users\Brian\Desktop\SURP\Pycharm\week_3_deep_q_lunar_landing\venv\lib\site-packages\gym\envs\registration.py",line 19,in load
    fn = getattr(mod,attr_name)
AttributeError: module 'gym.envs.Box2d' has no attribute 'LunarLander'

我已经寻找了此修复程序的答案,其中包括 pip install Box2D,但是当我运行时,我遇到了更多问题。第一个是没有安装 SWIG,但是我解决了这个问题,现在我收到了这个错误

(venv) C:\Users\Brian\Desktop\SURP\Pycharm\week_3_deep_q_lunar_landing>pip install Box2D
Collecting Box2D
  Using cached Box2D-2.3.2.tar.gz (427 kB)
Using legacy 'setup.py install' for Box2D,since package 'wheel' is not installed.
Installing collected packages: Box2D
    Running setup.py install for Box2D ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\brian\desktop\surp\pycharm\week_3_deep_q_lunar_landing\venv\scripts\python.exe' -u -c 'import io,os,sys,setuptools,tokenize; sys.argv[0] = '"'"'C:\\Users\\Public\\Documents\\Wondershare\\CreatorTemp\\pip-ins
tall-t0mlyzlm\\Box2d_51a5cdaa197d4949b5c03abb4053082a\\setup.py'"'"'; __file__='"'"'C:\\Users\\Public\\Documents\\Wondershare\\CreatorTemp\\pip-install-t0mlyzlm\\Box2d_51a5cdaa197d4949b5c03abb4053082a\\setup.py'"'"';f = getattr(tokeniz
e,'"'"'open'"'"',open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"
'))' install --record 'C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-record-5tmbzvt1\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\brian\desktop\surp\pycharm\week_3_deep_q_lunar_l
anding\venv\include\site\python3.9\Box2D'
         cwd: C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-install-t0mlyzlm\Box2d_51a5cdaa197d4949b5c03abb4053082a\
    Complete output (28 lines):
    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
    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/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\brian\desktop\surp\pycharm\week_3_deep_q_lunar_landing\venv\scripts\python.exe' -u -c 'import io,tokenize; sys.argv[0] = '"'"'C:\\Users\\Public\\Documents\\
Wondershare\\CreatorTemp\\pip-install-t0mlyzlm\\Box2d_51a5cdaa197d4949b5c03abb4053082a\\setup.py'"'"'; __file__='"'"'C:\\Users\\Public\\Documents\\Wondershare\\CreatorTemp\\pip-install-t0mlyzlm\\Box2d_51a5cdaa197d4949b5c03abb4053082a\\
setup.py'"'"';f = getattr(tokenize,'"'"'\n'"'"');f.close();exec(comp
ile(code,'"'"'exec'"'"'))' install --record 'C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-record-5tmbzvt1\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\brian\desktop\s
urp\pycharm\week_3_deep_q_lunar_landing\venv\include\site\python3.9\Box2D' Check the logs for full command output.

这完全让我感到困惑,因为错误告诉我现在说要获取不同版本的 Visual Studio 代码,但我使用的是 PyCharm。

我已经为此苦苦挣扎了一段时间,如果有人知道解决代码的主要错误或 pip 安装错误,那就太好了。

如果您需要更多信息,请告诉我。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)