环境问题
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]