[英]Gym's box 2d (openAI) doesn't install successfully (pip error)
I'm trying to do the follow code with OpenAI:我正在尝试使用 OpenAI 执行以下代码:
import gym
env = gym.make('CarRacing-v0')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample())
but it throws the error:但它会引发错误:
fn = getattr(mod, attr_name) AttributeError: module 'gym.envs.box2d' has no attribute 'CarRacing'
fn = getattr(mod, attr_name) AttributeError: 模块 'gym.envs.box2d' 没有属性 'CarRacing'
And then I try to install box2d by pip install box2d-py throwing this error:然后我尝试通过 pip install box2d-py 安装 box2d 并抛出此错误:
ERROR: Command errored out with exit status 1:
command: 'C:\Users\Junior\Anaconda\envs\gym\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Junior\\AppData\\Local\\Temp\\pip-install-w8awn22p\\box2d-py\\setup.py'"'"'; __file__='"'"'C:\\Users\\Junior\\AppData\\Local\\Temp\\pip-install-w8awn22p\\box2d-py\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Junior\AppData\Local\Temp\pip-record-netg1nlq\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Junior\Anaconda\envs\gym\Include\box2d-py'
cwd: C:\Users\Junior\AppData\Local\Temp\pip-install-w8awn22p\box2d-py\
Complete output (16 lines):
Using setuptools (version 45.2.0.post20200210).
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\Box2D
copying library\Box2D\Box2D.py -> build\lib.win-amd64-3.7\Box2D
copying library\Box2D\__init__.py -> build\lib.win-amd64-3.7\Box2D
creating build\lib.win-amd64-3.7\Box2D\b2
copying library\Box2D\b2\__init__.py -> build\lib.win-amd64-3.7\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: No such file or directory
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\Junior\Anaconda\envs\gym\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Junior\\AppData\\Local\\Temp\\pip-install-w8awn22p\\box2d-py\\setup.py'"'"'; __file__='"'"'C:\\Users\\Junior\\AppData\\Local\\Temp\\pip-install-w8awn22p\\box2d-py\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Junior\AppData\Local\Temp\pip-record-netg1nlq\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Junior\Anaconda\envs\gym\Include\box2d-py' Check the logs for full command output.
what I have to do to install it successfully?我必须做什么才能成功安装它?
Windows support is at present moment experimental ( source ). Windows 支持目前处于实验阶段(来源)。 That being said, on most of the occasions you will get it to work, but some of the functionality could be broken.
话虽如此,在大多数情况下,您可以让它工作,但某些功能可能会被破坏。 Proceed with caution.
谨慎行事。
Here's what could work:以下是可行的方法:
conda
to the PATH).conda
添加到 PATH)。conda create -c conda-forge -n gymenv swig pip
- create base environment. conda create -c conda-forge -n gymenv swig pip
- 创建基础环境。conda activate gymenv
- activate it. conda activate gymenv
- 激活它。pip install Box2D gym
- install base gym with Box2D. pip install Box2D gym
- 使用 Box2D 安装基础健身房。pip install gym[all]
- install all components of Gym. pip install gym[all]
- 安装 Gym 的所有组件。 You might run into errors. If you get build errors on missing compilers, install Visual Studio Built Tools .如果您在缺少的编译器上遇到构建错误,请安装Visual Studio Built Tools 。
Depending on the component you're using, you might need eg pystan
.根据您使用的组件,您可能需要例如
pystan
。 Activate then the conda environment and install it, ie conda install pystan
.然后激活 conda 环境并安装它,即
conda install pystan
。
An alternative could be to try to install Gym directly through conda:另一种方法是尝试通过 conda 直接安装 Gym:
conda create -c conda-forge -c powerai -n gymenv gym swig pip pystan
This will install gym
from powerai channel .这将从powerai频道安装
gym
。 Might work , but mind that it's not the latest nor seems to be supported by devs.可能有用,但请注意,它不是最新的,也似乎不受开发人员的支持。
In my case, I used the conda
to install Gym's Box2D:就我而言,我使用
conda
安装 Gym 的 Box2D:
conda install swig
conda install -c conda-forge gym-box2d
and got rid of this error.并摆脱了这个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.