我在创建gym_super_mario_bros env 时遇到问题并且出现 KeyError: 'render_modes'

Cra*_*yec 5 python artificial-intelligence reinforcement-learning jupyter-notebook openai-gym

我正在尝试遵循 Nicholas Renotte 教程的“使用 Python 构建马里奥 AI 模型 | 游戏强化学习”,但由于出现一些错误而无法继续。

这是我的代码:

!pip install gym_super_mario_bros==7.3.0 nes_py

# Import the game
import gym_super_mario_bros
# Import the Joypad wrapper
from nes_py.wrappers import JoypadSpace
# Import the simplified controls
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT

# Setup game
env = gym_super_mario_bros.make('SuperMarioBros-v0')
env = JoypadSpace(env, SIMPLE_MOVEMENT)
   
Run Code Online (Sandbox Code Playgroud)

这行代码: env = gym_super_mario_bros.make('SuperMarioBros-v0')导致以下错误:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_16900\3897944130.py in <module>
      1 # Setup game
----> 2 env = gym_super_mario_bros.make('SuperMarioBros-v0')
      3 env = JoypadSpace(env, SIMPLE_MOVEMENT)

D:\Anaconda\envs\gamesAi\lib\site-packages\gym\envs\registration.py in make(id, max_episode_steps, autoreset, new_step_api, disable_env_checker, **kwargs)
    623     # If we have access to metadata we check that "render_mode" is valid
    624     if hasattr(env_creator, "metadata"):
--> 625         render_modes = env_creator.metadata["render_modes"]
    626 
    627         # We might be able to fall back to the HumanRendering wrapper if 'human' rendering is not supported natively

KeyError: 'render_modes'


Run Code Online (Sandbox Code Playgroud)

我已经尝试使用 python 3.7 而不是 3.9 并重新安装软件包

小智 1

大多数自定义环境尚未为 0.25 版本做好准备。将版本更改为 0.24.1 应该可以解决该问题。

尝试:

pip install gym=0.24.1
Run Code Online (Sandbox Code Playgroud)

亲切的问候