3

I'm running Python3 (3.8.10) and am attempting a tutorial with the gym_super_mario_bros (7.3.0) and nes_py libraries. I followed various tutorials code and tried on multiple computers but get an error. I have tried to adjust some of the parameters like adding a 'truncated' variable to the list of values to return. As this is a tutorial level example I'm curious what is wrong. It looks like something with env.step(). Below is the code:

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 step in range(1000):
        if done:
                env.reset()
        state, reward, done, info = env.step(env.action_space.sample())
        env.render()
env.close()

The error I get is below:

/home/d/.local/lib/python3.8/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(
/home/d/.local/lib/python3.8/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(
/home/d/.local/lib/python3.8/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(
Traceback (most recent call last):
  File "mario.py", line 12, in <module>
    state, reward, done, info = env.step(env.action_space.sample())
  File "/home/d/.local/lib/python3.8/site-packages/nes_py/wrappers/joypad_space.py", line 74, in step
    return self.env.step(self._action_map[action])
  File "/home/d/.local/lib/python3.8/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)

Any guidance is appreciated, thank you!

2 Answers2

3

Move to "...../python3.8/site-packages/gym/wrappers/time_limit.py".And delete all "truncated"

  • This worked, thank you very much! I always try to steer away from editing library code lol, but sweet! – evenspaghetti Oct 14 '22 at 14:50
  • 1
    I am using Kaggle Notebooks and I am getting the same error. I do not really understand what this answer means. Please help me out – abzd Jun 18 '23 at 18:15
0

Open up your venv, and run pip uninstall gym followed by pip install gym==0.23.1

They apparently changed the API in some update to the gym library. It now returns a fifth value, called truncate, in the order (state, reward, done, truncate, info). Even though the modifying the library files may work as intended, like suggested in another answer here, it's best to never change a library's source to prevent breaking something else deeper inside.