windows系统下安装最新版gym的安装方法(此时最新版的gym为0.24.0,gym==0.24.0)
当前gym的最新版本为0.24.0,本篇介绍对gym[atari]==0.24.0进行安装。
使用pip安装:
pip install gym[atari]

可以看到此时安装的是ale_py而不是atari_py库。
运行测试代码:
import gym
env=gym.make("Pong-v0")
print(env)
env.reset()
结果报错:

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]
此时再运行,结果:

证明问题已解决,gym[atari]已经成功安装。
测试代码:
import time
import gym env = gym.make('BreakoutNoFrameskip-v4')
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()
发现报错:

查看报错的代码地址:lib\site-packages\gym\core.py

def render(self, mode="human"):
"""Renders the environment. A set of supported modes varies per environment. (And some
third-party environments may not support rendering at all.)
By convention, if mode is: - human: render to the current display or terminal and
return nothing. Usually for human consumption.
- rgb_array: Return a numpy.ndarray with shape (x, y, 3),
representing RGB values for an x-by-y pixel image, suitable
for turning into a video.
- ansi: Return a string (str) or StringIO.StringIO containing a
terminal-style text representation. The text can include newlines
and ANSI escape sequences (e.g. for colors). Note:
Make sure that your class's metadata 'render_modes' key includes
the list of supported modes. It's recommended to call super()
in implementations to use the functionality of this method. Example:
>>> import numpy as np
>>> class MyEnv(Env):
... metadata = {'render_modes': ['human', 'rgb_array']}
...
... def render(self, mode='human'):
... if mode == 'rgb_array':
... return np.array(...) # return RGB frame suitable for video
... elif mode == 'human':
... ... # pop up a window and render
... else:
... super().render(mode=mode) # just raise an exception Args:
mode: the mode to render with, valid modes are `env.metadata["render_modes"]`
"""
raise NotImplementedError
可以看到由于gym的版本升级曾经多个版本的gym的测试代码已经不能继续使用了,于是我们进行修改:

再次报错:

报错信息的全部:
"render(mode='human') is deprecated. Please supply `render_mode` when "
gym.error.Error: render(mode='human') is deprecated. Please supply `render_mode` when constructing your environment, e.g., gym.make(ID, render_mode='human'). The new `render_mode` keyword argument supports DPI scaling, audio, and native framerates.
从上面的报错信息可以知道gym设置了一个绘图显示模式`render_mode,如果想使用绘图显示的功能就需要在创建环境的时候进行设置,形式如gym.make(ID, render_mode='human')。
修改后的代码:
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):
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
time.sleep(0.01)
env.close()
可以正常运行并绘制显示图像:

通过对上面的代码测试,可以知道在设置绘图显示模式`render_mode时进行绘图的步骤为 env.reset() 和 env.step(action),在执行这两步操作时会自动进行绘图显示。
查看位于lib\site-packages\gym\envs\atari\environment.py中的代码:
def render(self, mode: str) -> Any:
"""
Render is not supported by ALE. We use a paradigm similar to
Gym3 which allows you to specify `render_mode` during construction.
For example,
gym.make("ale-py:Pong-v0", render_mode="human")
will display the ALE and maintain the proper interval to match the
FPS target set by the ROM.
"""
if mode == "rgb_array":
return self.ale.getScreenRGB()
elif mode == "human":
raise error.Error(
(
"render(mode='human') is deprecated. Please supply `render_mode` when "
"constructing your environment, e.g., gym.make(ID, render_mode='human'). "
"The new `render_mode` keyword argument supports DPI scaling, "
"audio, and native framerates."
)
)
else:
raise error.Error(
f"Invalid render mode `{mode}`. Supported modes: `rgb_array`."
)
可以知道在新版本的gym中一共存在两个环境模式,一个是'human'模式,一个是`rgb_array`模式。如果不在创建环境时通过gym.make(ID, render_mode='human')设置绘图显示模式的话默认就是`rgb_array`模式。
虽然新版的gym的改动不大但是对于习惯使用旧版本的gym的人来说还是有些不方便的,不过说一个敲黑板的事情,那就是如果你要发布你的依赖gym环境的强化学习代码一定要把gym的版本号和ale_py版本号或atari_py版本号给标注出来,否则不一定gym未来版本一升级你以前的代码就会运行报错,挨个试验旧版本的gym是个很困难的工作,所以发布代码时标注好你所使用的gym版本号是很有必要的。
=================================================
windows系统下安装最新版gym的安装方法(此时最新版的gym为0.24.0,gym==0.24.0)的更多相关文章
- windows系统下简单nodej.s环境配置 安装
国内目前关注最高,维护最好的一个关于nodejs的网站应该是http://www.cnodejs.org/ windows系统下简单nodejs环境配置. 第一步:下载安装文件 下载地址:官网 htt ...
- windows系统下简单node.js环境配置 安装
国内目前关注最高,维护最好的一个关于nodejs的网站应该是http://www.cnodejs.org/ windows系统下简单nodejs环境配置. 第一步:下载安装文件 下载地址:官网 htt ...
- windows系统下python2.7.14版本的安装
[前言] 本文主要对window下如何安装Python进行图解说明. [正文] 步骤一 从官网下载相应的版本(本文以2.7.14为例),下载地址:https://www.python.org/down ...
- Python3.x:pyodbc连接Sybase数据库操作(Windows系统下DNS模式)
Python3.x:pyodbc连接Sybase数据库操作(Windows系统下DNS模式) 一.安装模块pyodbc pip install pyodbc 二.配置odbc数据源 (1).windo ...
- Windows 7/8/10 系统下Laravel框架的开发环境安装及部署详解(Vagrant + Homestead)
注意! laravel/homestead box项目地址已经不再是原来的 https://atlas.hashicorp.com/laravel/boxes/homestead 而已经变更成 htt ...
- windows系统下安装MySQL
可以运行在本地windows版本的MySQL数据库程 序自从3.21版以后已经可以从MySQL AB公司获得,而且 MYSQL每日的下载百分比非常大.这部分描述在windows上安装MySQL的过程. ...
- Windows系统下Nginx的安装与配置
Nginx是lgor Sysoev在2004年的时候为俄罗斯访问量第二大的rambler.ru站点设计开发的,发布至今,凭借开源的力量,已经接近成熟与完善.其功能丰富,可作为HTTP服务器,也可作为反 ...
- Tomcat Windows 系统下安装及注意事项
1 获取Tomcat 安装包 http://tomcat.apache.org/ tar.gz 文件是Linux系统下的安装版本 exe文件是 Windows系统下的安装版本 zip 文件是Wind ...
- windows系统下简单nodejs安装及环境配置
相信对于很多关注javascript发展的同学来说,nodejs已经不是一个陌生的词眼,这里不想谈太多的nodejs的相关信息.只说一下,windows系统下简单nodejs环境配置 相信 ...
- Windows系统下安装zabbix客户端
简单介绍如何在windows系统下安装zabbix客户端 1. 首先下载和zabbix服务端大版本相同的windows客户端 例如我服务端安装的是zabbix-3.4.14.tar.gz ...
随机推荐
- restful接口返回JSONObject和父类抽象实现类设计,请求头获取sign和支付宝RSA签名验签工具类方法
restful接口返回JSONObject和父类抽象实现类设计,请求头获取sign和支付宝RSA签名验签工具类方法 1.JSONObject可以通用数据的灵活性,类似Map数据,数据字段不清晰.具体返 ...
- Jx9 虚拟机
一.Jx9 虚拟机的生命周期 加载 Jx9 脚本 jx9_compile() 或 jx9_compile_file(),加载编译成功后,Jx9 引擎将自动创建一个实例 (jx9_vm) 并且返回指向此 ...
- K-means聚类是一种非常流行的聚类算法
K-means聚类是一种非常流行的聚类算法,它的目标是将n个样本划分到k个簇中,使得每个样本属于与其最近的均值(即簇中心)对应的簇,从而使得簇内的方差最小化.K-means聚类算法简单.易于实现,并且 ...
- WatchDog:一款.NET开源的实时应用监控系统
项目介绍 WatchDog是一个开源(MIT License).免费.针对ASP.Net Core Web应用程序和API的实时应用监控系统.开发者可以实时记录和查看他们的应用程序中的消息.事件.HT ...
- xshell+ssh+网络+加密
使用xshell+ssh用于管理linux服务器,大概是目前最为流行的方式. 这个工具和技术涉及到: 计算机网络 加密解密 虽然不是专门的系统工程师,但还是相对频繁使用这套工具,有时候难免遇到一些不知 ...
- Xilinx-HDF的文件内容
Xilinx-HDF文件 原文:分享:HDF文件的更多用途 Xilnx Vivado能导出HDF文件,给Xilnx SDK创建软件工程.HDF文件的还可以有更多用途. HDF文件是一个zip文件,可以 ...
- Java 把多个音频拼接成一个
在Java中,将多个音频文件拼接成一个通常需要使用一些专门的音频处理库,因为Java标准库并不直接支持音频文件的合并.一个常用的库是JAVE2(Java Audio Video Encoder)或JL ...
- debian11安装备忘
1. 网卡驱动 参考网址:如何安装Debian RTL8821CE驱动? 2. 分辨率 貌似还是有点问题,还要进一步研究一下 参考网址:虚拟机中debian11修改控制台(console)分辨率|li ...
- 洛谷P1020
又是一道做的很麻的题,准确来说感觉这不是一道很好的dfs题,没有体现dfs的一些特点 反而感觉是在考察dp,刚开始也是按照我的思路交了3次都没过 原本以为所选的数应该都是由上一次的最大值推出来的,后面 ...
- 四 黑马程序员-java面向对象(上)
一.:面向对象 (1)面向对象:是基于面向过程的一种思想. 面向过程:以函数为基础,关注实现过程. 面向对象:以对象为基础,关注实现结果. (2)面向对象的思想特点: A:是一种更符合人们思考习惯的思 ...