环境问题
conda python==3.9
pip install gym==0.25.2
conda install swig
pip install gym[box2d]
gym版本不同的时候,env的函数输出是不一样的
#gym==0.25.2
obs = env.reset()
img = cv2.cvtColor(env.render()[0], cv2.COLOR_RGB2BGR)
next_obs, reward, done, _ = env.step(action)
#gym==0.26.0
obs = env.reset()[0]
img = cv2.cvtColor(env.render(), cv2.COLOR_RGB2BGR)
next_obs, reward, done, tmp1, tmp2 = env.step(action)
错误一、env.render() 没有显示
版本问题,现在代码改了。
env = gym.make("CliffWalking-v0", render_mode="human")
observation = env.reset()
或者
env = gym.make("CliffWalking-v0", render_mode="rgb_array")
observation = env.reset()
img = cv2.cvtColor(env.render(), cv2.COLOR_RGB2BGR)
# gym==0.25.2 的话,上面那个改成env.render()[0]
cv2.imshow("test", img)
cv2.waitKey(1)
错误二、‘CartPoleEnv’ object has no attribute ‘seed’
gym本过版高,导致该函数已被移除,尝试安装了更低版本的gym,完美解决问题。(当然也可以重写 env.seed(seed)的相关函数)
pip install gym==0.25.2
或者直接把env.seed(1)注释掉也行
错误三、安装gym[box2d]失败
ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects
这是缺少swig.exe可执行文件导致的,先装swig再装gym[box2d]即可
conda install swig
pip install gym[box2d]
错误四、找不到ROM空间
gym.make加载游戏Breakout的时候报错,说是这个版本移除了ROM,要额外安装
gym.error.Error: We’re Unable to find the game “Breakout”. Note: Gym no longer distributes ROMs. If you own a license to use the necessary ROMs for research purposes you can download them via pip install gym[accept-rom-license]
. Otherwise, you should try importing “Breakout” via the command ale-import-roms
. If you believe this is a mistake perhaps your copy of “Breakout” is unsupported. To check if this is the case try providing the environment variable PYTHONWARNINGS=default::ImportWarning:ale_py.roms
. For more information see: https://github.com/mgbellemare/Arcade-Learning-Environment#rom-management
默认你安装好了ale_py,swig那些库。
先到Atari官网上下载Roms.zip,解压缩,把roms下面的所有文件(各种.bin)移动到创建的环境文件夹下,我是用conda创建的RL虚拟环境,就把文件都移动到目录C:\Users\19256.conda\envs\RL\Lib\site-packages\ale_py\roms下,然后再RL环境下运行AutoROM --accept-license, 就可以看到它安装了一系列环境
备注:我是ale-import-roms ROMS/ 一直报错,所以才直接移动到环境目录下,如果各位这个可以运行那当然最好