(已解决)no “render_mode“和got an u

@[TOC]

前言:

清早起来,验收晚上跑的马里奥模型,一测试,发现炼丹炉爆炸了。
先后出现了
warnings.warn("You tried to call render() but no "render_mode" was passed to the env constructor.")

Box(0, 255, (4, 240, 256), uint8) observation space is not supported 等问题,下文将分析如何解决,请通读全文,再进行安装尝试!!。


问题1. render的render_mode问题

当我在运行render()的时候,遇到了这个问题
warnings.warn("You tried to call render() but no ‘render_mode’ was passed to the env constructor.")
意思是说你要运行render,怎么能不告诉我render_mode呢?那我们就加上。

1
python复制代码environment = gym_super_mario_bros.make('SuperMarioBros-v0',render_mode = "human")

怎么还是寄!遇到以下问题
TypeError: SuperMarioBrosEnv.__init__() got an unexpected keyword argument 'render_mode'
这就好笑了,超级玛丽的库没写render_mode而我们调用却需要!!这就十分吊诡了。
这是由于库更新了导致的,我们需要重新配置库。
笔者广阅群文,发现完全没有人说这个问题,在各种评论区畅游得到一个解决方案如下:

1
2
3
4
5
bash复制代码pip install nes-py
pip install gym-super-mario-bros==7.3.0
pip install setuptools==65.5.0 "wheel<0.40.0"
pip install gym==0.21.0
pip install stable-baselines3[extra]==1.6.0

问题2. baselines3版本问题

大喜过望,开始尝试,运行最后一个的时候

ERROR: No matching distribution found for ale-py==0.7.4; extra == "extra"

在这里插入图片描述
¯﹃¯ (博主当时表情)
说是缺少ale-py库,寄。于是我们再次安装ale-py==0.7.4
在这里插入图片描述
????啊???0.7.4版本,他没了!¯﹃¯
再pypl上发现官方只有8版本以上了,经过尝试,我们可以退而求其次安装

1
python复制代码pip install baselines3==1.6.0

安装成功!

问题3. cloudpickle版本问题

我们安装好了之后再次运行,之前的问题也确实没有了,又遇到了
在这里插入图片描述

或者NotImplementedError: Box(0, 255, (4, 240, 256), uint8) observation space is not supported
这是由于cloudpickle版本和训练版本不对应,或者cloudpickle版本不对导致的。
请卸载cloudpickle,请输入

1
python复制代码pip install cloudpickle==3.0.0

然后按照马里奥系列第三章马里奥游戏ai训练与保存重新训练与当前版本一致的模型就好啦~


完整解法

如果按照以下解法安装仍然失败,可能是由于库连体的问题,就是一些库比如baselines3和gym会附带安装其他库,请你也注意其版本,如果需要,可以删除重装。如果还是不行,建议把所有相关库删掉,然后依次执行以下代码。

1
2
3
4
5
6
py复制代码pip install nes-py
pip install gym-super-mario-bros==7.3.0
pip install setuptools==65.5.0 "wheel<0.40.0"
pip install gym==0.21.0
pip install stable-baselines3==1.6.0
pip install cloudpickle==3.0.0

如果还是不行,我附上我的各个库的版本(相关的),请根据自己的需要查看。输入pip list 即可查看自己的库。这些库的版本如果都对,是可以运行render之类的显示指令的。请一一对应检查。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
c复制代码ale-py                     0.8.1
atari-py 0.2.6
cloudpickle 3.0.0
gym 0.21.0
gym-notices 0.0.8
gym-super-mario-bros 7.3.0
gymnasium 0.28.1
importlib-metadata 4.13.0
importlib_resources 6.4.0
MarkupSafe 2.1.3
matplotlib 3.8.2
matplotlib-inline 0.1.6
nes-py 8.2.1
numpy 1.26.0
opencv-contrib-python 4.9.0.80
opencv-python 4.9.0.80
pip 24.0
pygame 2.5.2
setuptools 65.5.0
Shimmy 1.3.0
tensorboard 2.16.2
tensorboard-data-server 0.7.2
tensorboardX 2.6.2.2
torch 2.1.2+cu118
torchaudio 2.1.2+cu118
torchvision 0.16.2+cu118
wheel 0.38.4

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%