> 文档中心 > AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘

AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘


问题截图

AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘

问题描述

运行需要gym的python程序时候,已经下载了gym后仍然报:AttributeError: module ‘gym.envs.box2d’ has no attribute ‘LunarLander’

问题原因

需要导入gym的LunarLander,单独安装swig和box2d box2d-kengz就可以了

解决办法

安装swig和box2d box2d-kengz

(1)安装swig

pip install swig 

AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘
如果出现上面: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLEOFError(8, ‘EOF occurred in violation of protocol (_ssl.c:852)’),)’: /simple/swig/
那就是镜像的原因了,我们换一个下载镜像就可以了,使用下面的指令即可:

pip install swig -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

(2)安装box2d box2d-kengz

pip install box2d box2d-kengz -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘

会报错 ERROR: Failed building wheel for box2d-kengz错误,这时候需要自己手动下载,然后在命令行执行pip install

下载链接box2d box2d-kengz,找到自己需要的(cp36指的是python3.6,其他类似)
AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘
下载之后放在安装python的目录下面(下面是我自己的,根据自己的具体情况更改)
AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘
然后使用命令行安装一下
AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘

可以在settings中看下上面的两个是否安装成功

成功截图

AttributeError: module ‘gym.envs.box2d‘ has no attribute ‘LunarLander‘

国际新闻