我正在尝试遵循 Nicholas Renotte 教程的“使用 Python 构建 Mario 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)
这行代码:
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'
我已经尝试使用 python 3.7 而不是 3.9 并重新安装软件包
大多数自定义环境尚未准备好用于 0.25 版本。将版本更改为 0.24.1 应该可以解决问题。
尝试:
pip install gym=0.24.1
亲切的问候
我相信您需要将错误行替换为以下内容:
env = gym_super_mario_bros.make('SuperMarioBros-v0',apply_api_compatibility=True,render_mode="human" )