英文:
ValueError: not enough values to unpack (expected 5, got 4) when using nes_py and gym_super_mario_bros
问题
在运行以下代码时,直接从官方PyPi文档中复制:
from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
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 step in range(5000):
if done:
state = env.reset()
state, reward, done, info = env.step(env.action_space.sample())
env.render()
env.close()
但在运行代码时,我收到以下错误:
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\envs\registration.py:555: UserWarning: WARN: The environment SuperMarioBros-v0 is out of date. You should consider upgrading to version `v3`.
logger.warn(
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\utils\passive_env_checker.py:195: UserWarning: WARN: The result returned by `env.reset()` was not a tuple of the form `(obs, info)`, where `obs` is a observation and `info` is a dictionary containing additional information. Actual type: `<class 'numpy.ndarray'>`
logger.warn(
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\utils\passive_env_checker.py:219: DeprecationWarning: WARN: Core environment is written in old step API which returns one bool instead of two. It is recommended to rewrite the environment with new step API.
logger.deprecation(
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\utils\passive_env_checker.py:225: DeprecationWarning: `np.bool8` is a deprecated alias for `np.bool_`. (Deprecated NumPy 1.24)
if not isinstance(done, (bool, np.bool8)):
Traceback (most recent call last):
File "d:\SEM 6\Minor Project\super mario\test.py", line 11, in <module>
state, reward, done, info = env.step(env.action_space.sample())
File "C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\nes_py\wrappers\joypad_space.py", line 74, in step
return self.env.step(self._action_map[action])
File "C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\wrappers\time_limit.py", line 50, in step
observation, reward, terminated, truncated, info = self.env.step(action)
ValueError: not enough values to unpack (expected 5, got 4)
所有的第一个警告都可以忽略,但最后一个ValueError是我无法摆脱的问题。
我尝试安装了nes_py
和gym_super_mario_bros
的先前版本。我在首次运行时使用了Python版本3.10。我甚至降级到Python版本3.8.10,但问题仍然存在。
如果有人能指导我解决这个错误,对我来说将非常有帮助。谢谢。
英文:
While running the following code
from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
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 step in range(5000):
if done:
state = env.reset()
state, reward, done, info = env.step(env.action_space.sample())
env.render()
env.close()
which was copied directly from the official PyPi Doc
but while running the code, i am getting the following error
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\envs\registration.py:555: UserWarning: WARN: The environment SuperMarioBros-v0 is out of date. You should consider upgrading to version `v3`.
logger.warn(
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\utils\passive_env_checker.py:195: UserWarning: WARN: The result returned by `env.reset()` was not a tuple of the form `(obs, info)`, where `obs` is a observation and `info` is a dictionary containing additional information. Actual type: `<class 'numpy.ndarray'>`
logger.warn(
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\utils\passive_env_checker.py:219: DeprecationWarning: WARN: Core environment is written in old step API which returns one bool instead of two. It is recommended to rewrite the environment with new step API.
logger.deprecation(
C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\utils\passive_env_checker.py:225: DeprecationWarning: `np.bool8` is a deprecated alias for `np.bool_`. (Deprecated NumPy 1.24)
if not isinstance(done, (bool, np.bool8)):
Traceback (most recent call last):
File "d:\SEM 6\Minor Project\super mario\test.py", line 11, in <module>
state, reward, done, info = env.step(env.action_space.sample())
File "C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\nes_py\wrappers\joypad_space.py", line 74, in step
return self.env.step(self._action_map[action])
File "C:\Users\MSI\AppData\Local\Programs\Python\Python38\lib\site-packages\gym\wrappers\time_limit.py", line 50, in step
observation, reward, terminated, truncated, info = self.env.step(action)
ValueError: not enough values to unpack (expected 5, got 4)
All the first warnings are okay but the last ValueError is something that I cannot get rid of.
I have tried installing previous versions of nes_py
and gym_super_mario_bros
. I had python version 3.10 while running it for the first time. I have even downgraded to python version 3.8.10 but still the issue persists.
If someone would be able to guide me to resolve this error then it would be very helpful to me.
Thanks.
答案1
得分: 1
似乎gym
本身存在一些问题。我使用pip uninstall gym
卸载了gym
,然后重新安装了一个较旧的版本 - pip install gym==0.23.1
,这解决了错误。
非常感谢r/learnpython中的u/eleqtriq。他帮助我解决了这个错误。
这是Reddit帖子的链接 - 无法让gym_super_mario_bros工作
英文:
It seems like there is some problem with gym
itself.
I uninstalled gym with pip uninstall gym
and then re-installed an older version - pip install gym==0.23.1
and that fixed the error.
A big thanks to u/eleqtriq from r/learnpython. He helped me solve this error.
Here's a link to the Reddit thread - Cannot get gym_super_mario_bros to work
答案2
得分: 0
似乎可能是与 openai/gym 包的依赖关系有问题。也许检查一下您安装的 openai/gym 的版本。
英文:
Looks like it might be a dependency problem with the openai/gym package. Maybe check the version of your installed openai/gym.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论