gym
gym copied to clipboard
[Bug Report] Value Error: env.step(action)
When setting up my envs, I get Value Error messages for my env.step(env.action_space.sample()) If you can help that will be greatly appreciated! (Mac OS, Jupyter Lab)
Here's the Code:
!pip3 install gym-super-mario-bros nes_py !pip3 install gym
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()
Error Message:
ValueError Traceback (most recent call last) Cell In [45], line 5 3 if done: 4 state = env.reset() ----> 5 state, reward, done, info = env.step(env.action_space.sample()) 6 env.render() 8 env.close()
File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nes_py/wrappers/joypad_space.py:74, in JoypadSpace.step(self, action) 59 """ 60 Take a step using the given action. 61 (...) 71 72 """ 73 # take the step and record the output ---> 74 return self.env.step(self._action_map[action])
File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gym/wrappers/time_limit.py:50, in TimeLimit.step(self, action)
39 def step(self, action):
40 """Steps through the environment and if the number of steps elapsed exceeds max_episode_steps
then truncate.
41
42 Args:
(...)
48
49 """
---> 50 observation, reward, terminated, truncated, info = self.env.step(action)
51 self._elapsed_steps += 1
53 if self._elapsed_steps >= self._max_episode_steps:
ValueError: not enough values to unpack (expected 5, got 4)
- [x] I have checked that there is no similar [issue]
Hey, we just launched gymnasium, a fork of Gym by the maintainers of Gym for the past 18 months where all maintenance and improvements will happen moving forward. Could you please move this over to the new repo?
If you'd like to read more about the story behind the backstory behind this and our plans going forward, click here.
Of course! I'm sorry for adding this in the wrong repo. Thank you for your assistance!
Have you solved the problem now? I have encountered the same problem
The gymnasium issue https://github.com/Farama-Foundation/Gymnasium/issues/77
from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
import gym
env = gym.make('SuperMarioBros-v0', apply_api_compatibility=True, render_mode="human")
env = JoypadSpace(env, SIMPLE_MOVEMENT)
done = True
env.reset()
for step in range(5000):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
if done:
env.reset()
env.close()
Try this, they update prob if the library supports it.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Games Environments """"""""""""""""""""""""""""""""""""""""""""""""""""""""" env = gym.make("ALE/KungFuMaster-v5", render_mode='human') n_outputs = env.action_space.n obs = env.reset() observation, reward, done, info, prob = env.step(1)
@jkaewprateep This code is incorrect! For Gym v26, the correct code is
env = gym.make("ALE/KungFuMaster-v5", render_mode='human')
n_outputs = env.action_space.n
obs, info = env.reset()
observation, reward, terminated, truncated, info = env.step(1)
That is the variable name.