安装gym-super-mario-bros后运行程序报ValueError: not enough values to unpack (expected 5, got 4)
解决gym-super-mario-bros运行时的ValueError问题
这个错误是由于gym-super-mario-bros与依赖的nes-py版本不兼容导致的——新版本nes-py的环境step()方法返回值从5个改成了4个,但旧版gym-super-mario-bros仍期望接收5个值,从而触发解包错误。
修复步骤:
- 卸载现有冲突版本
pip uninstall -y gym-super-mario-bros nes-py
- 安装指定兼容版本
先安装稳定兼容的nes-py版本,再安装gym-super-mario-bros:
pip install nes-py==8.2.1 pip install gym-super-mario-bros
- 验证修复
运行以下测试代码确认问题解决:
import gym_super_mario_bros from nes_py.wrappers import JoypadSpace from gym_super_mario_bros.actions import SIMPLE_MOVEMENT # 创建游戏环境 env = gym_super_mario_bros.make('SuperMarioBros-v0') env = JoypadSpace(env, SIMPLE_MOVEMENT) done = True for _ in range(1000): if done: state = env.reset() # 执行随机动作 state, reward, done, info = env.step(env.action_space.sample()) env.render() env.close()
内容的提问来源于stack exchange,提问作者Pranav Joshi
相关产品推荐
相关产品推荐

