当前gym的最新版本为0.24.0,本篇介绍对gym[atari]==0.24.0进行安装。

 

 

使用pip安装:

pip install gym[atari]

 

 

windows系统下安装最新版gym的安装方法(此时最新版的gym为0.24.0,gym==0.24.0)_运行测试

 


 

 

可以看到此时安装的是ale_py而不是atari_py库。

 

 

运行测试代码:

 

import gym
env=gym.make("Pong-v0")
print(env)
env.reset()

 

结果报错:

windows系统下安装最新版gym的安装方法(此时最新版的gym为0.24.0,gym==0.24.0)_python_02

 

f'We\'re Unable to find the game "{self._game}". Note: Gym no longer distributes ROMs. '
gym.error.Error: We're Unable to find the game "Pong". 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 "Pong" via the command `ale-import-roms`. If you believe this is a mistake perhaps your copy of "Pong" 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

 

 

根据报错的信息我们知道是因为没有安装atari游戏对应的ROMs的bin文件,我们可以选择手动下载后添加到ale_py库中,但是根据报错信息的提醒我们知道可以使用命令:pip install gym[accept-rom-license] 来进行安装。

执行:

pip install gym[accept-rom-license]

 

此时再运行,结果:

windows系统下安装最新版gym的安装方法(此时最新版的gym为0.24.0,gym==0.24.0)_杂谈_03

 


 证明问题已解决,gym[atari]已经成功安装。

 

 

 

 

 

测试代码:

绘图版:

 

import time
import gym

env = gym.make('BreakoutNoFrameskip-v4', render_mode='human')
print("Observation Space: ", env.observation_space)
print("Action Space ", env.action_space)

obs = env.reset()
for i in range(1000):
# env.render()
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
time.sleep(0.01)
env.close()