在JupyterLab上使用Python设置gym_super_mario_bros环境时出现OverflowError

问题描述 投票:0回答:1

我一直在遵循 YouTube 上的教程 (https://youtu.be/2eeYqJ0uBKE?si=Vx6gybqKh3ApSfXV) 使用 Python 构建超级马里奥 AI 模型。但是,在设置gym_super_mario_bros环境时,我遇到了OverflowError。这是我正在使用的代码:

# 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)

这是错误:

---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
Cell In[3], line 2
      1 # Setup game
----> 2 env = gym_super_mario_bros.make('SuperMarioBros-v0')
      3 env = JoypadSpace(env, SIMPLE_MOVEMENT)

File /Volumes/-/mario ai/mario/lib/python3.10/site-packages/gym/envs/registration.py:592, in make(id, max_episode_steps, autoreset, disable_env_checker, **kwargs)
    588 else:
    589     # Assume it's a string
    590     env_creator = load(spec_.entry_point)
--> 592 env = env_creator(**_kwargs)
    594 # Copies the environment creation specification and kwargs to add to the environment specification details
    595 spec_ = copy.deepcopy(spec_)

File /Volumes/-/mario ai/mario/lib/python3.10/site-packages/gym_super_mario_bros/smb_env.py:52, in SuperMarioBrosEnv.__init__(self, rom_mode, lost_levels, target)
     50 rom = rom_path(lost_levels, rom_mode)
     51 # initialize the super object with the ROM path
---> 52 super(SuperMarioBrosEnv, self).__init__(rom)
     53 # set the target world, stage, and area variables
     54 target = decode_target(target, lost_levels)

File /Volumes/-/mario ai/mario/lib/python3.10/site-packages/nes_py/nes_env.py:126, in NESEnv.__init__(self, rom_path)
    124     raise ValueError('ROM has trainer. trainer is not supported.')
    125 # try to read the PRG ROM and raise a value error if it fails
--> 126 _ = rom.prg_rom
    127 # try to read the CHR ROM and raise a value error if it fails
    128 _ = rom.chr_rom

File /Volumes/-/mario ai/mario/lib/python3.10/site-packages/nes_py/_rom.py:204, in ROM.prg_rom(self)
    202 """Return the PRG ROM of the ROM file."""
    203 try:
--> 204     return self.raw_data[self.prg_rom_start:self.prg_rom_stop]
    205 except IndexError:
    206     raise ValueError('failed to read PRG-ROM on ROM.')

File /Volumes/-/mario ai/mario/lib/python3.10/site-packages/nes_py/_rom.py:198, in ROM.prg_rom_stop(self)
    195 @property
    196 def prg_rom_stop(self):
    197     """The exclusive stopping index of the PRG ROM."""
--> 198     return self.prg_rom_start + self.prg_rom_size * 2**10

OverflowError: Python integer 1024 out of bounds for uint8

当我尝试使用gym_super_mario_bros.make('SuperMarioBros-v0') 创建环境时,会出现此错误。我使用的是 Python 3.10 和最新版本的gym_super_mario_bros,它们都在我的 Mac 上的 JupyterLab 上运行。有谁知道我如何修复此错误或可能导致此错误的原因是什么?

python macos jupyter-lab reinforcement-learning openai-gym
1个回答
0
投票

我在这里遵循不同的教程 - https://pytorch.org/tutorials/intermediate/mario_rl_tutorial.html,并收到相同的错误消息。

你尝试过旧的Python版本吗? Python 3.8.7 对我有用。

还必须使用旧版本的 Torch 和 numpy。 这是我的整个需求文件:

certifi==2024.7.4
charset-normalizer==3.3.2
cloudpickle==3.0.0
colorama==0.4.6
filelock==3.15.4
fsspec==2024.6.1
gym==0.26.2
gym-notices==0.0.8
gym-super-mario-bros==7.4.0
idna==3.7
importlib_metadata==8.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
mpmath==1.3.0
nes_py==8.2.1
networkx==3.1
numpy==1.24.4
packaging==24.1
pillow==10.4.0
pyglet==1.5.21
requests==2.32.3
sympy==1.13.1
tensordict==0.3.0
torch==2.2.0
torchaudio==2.2.0
torchrl==0.3.0
torchvision==0.17.0
tqdm==4.66.5
typing_extensions==4.12.2
urllib3==2.2.2
zipp==3.19.2
© www.soinside.com 2019 - 2024. All rights reserved.