AttributeError: 'SuperMarioBrosEnv' object has no attribute 'render_mode' #1532
Labels
custom gym env
Issue related to Custom Gym Env
more information needed
Please fill the issue template completely
❓ Question
from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
import gym
Import Frame Stacker Wrapper and GrayScaling Wrapper
from gym.wrappers import GrayScaleObservation
Import Vectorization Wrappers
from stable_baselines3.common.vec_env import VecFrameStack, DummyVecEnv
Import Matplotlib to show the impact of frame stacking
from matplotlib import pyplot as plt
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)
env = GrayScaleObservation(env, keep_dim=True)
when i execute the line mentioned below:
4. Wrap inside the Dummy Environment
env = DummyVecEnv([lambda: env])
i got this error
C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\stable_baselines3\common\vec_env\patch_gym.py:49: UserWarning: You provided an OpenAI Gym environment. We strongly recommend transitioning to Gymnasium environments. Stable-Baselines3 is automatically wrapping your environments in a compatibility layer, which could potentially cause issues.
warnings.warn(
AttributeError Traceback (most recent call last)
Cell In[5], line 2
1 # 4. Wrap inside the Dummy Environment
----> 2 env = DummyVecEnv([lambda: env])
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py:30, in DummyVecEnv.init(self, env_fns)
29 def init(self, env_fns: List[Callable[[], gym.Env]]):
---> 30 self.envs = [_patch_env(fn()) for fn in env_fns]
31 if len(set([id(env.unwrapped) for env in self.envs])) != len(self.envs):
32 raise ValueError(
33 "You tried to create multiple environments, but the function to create them returned the same instance "
34 "instead of creating different objects. "
(...)
39 "Please read #1151 for more information."
40 )
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py:30, in (.0)
29 def init(self, env_fns: List[Callable[[], gym.Env]]):
---> 30 self.envs = [_patch_env(fn()) for fn in env_fns]
31 if len(set([id(env.unwrapped) for env in self.envs])) != len(self.envs):
32 raise ValueError(
33 "You tried to create multiple environments, but the function to create them returned the same instance "
34 "instead of creating different objects. "
(...)
39 "Please read #1151 for more information."
40 )
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\stable_baselines3\common\vec_env\patch_gym.py:58, in _patch_env(env)
49 warnings.warn(
50 "You provided an OpenAI Gym environment. "
51 "We strongly recommend transitioning to Gymnasium environments. "
52 "Stable-Baselines3 is automatically wrapping your environments in a compatibility "
53 "layer, which could potentially cause issues."
54 )
56 if "seed" in signature(env.unwrapped.reset).parameters:
57 # Gym 0.26+ env
---> 58 return shimmy.GymV26CompatibilityV0(env=env)
59 # Gym 0.21 env
60 return shimmy.GymV21CompatibilityV0(env=env)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\shimmy\openai_gym_compatibility.py:90, in GymV26CompatibilityV0.init(self, env_id, make_kwargs, env)
87 self.action_space = _convert_space(self.gym_env.action_space)
89 self.metadata = getattr(self.gym_env, "metadata", {"render_modes": []})
---> 90 self.render_mode = self.gym_env.render_mode
91 self.reward_range = getattr(self.gym_env, "reward_range", None)
92 self.spec = getattr(self.gym_env, "spec", None)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\gym\core.py:229, in Wrapper.getattr(self, name)
227 if name.startswith("_"):
228 raise AttributeError(f"attempted to get missing private attribute '{name}'")
--> 229 return getattr(self.env, name)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\gym\core.py:229, in Wrapper.getattr(self, name)
227 if name.startswith("_"):
228 raise AttributeError(f"attempted to get missing private attribute '{name}'")
--> 229 return getattr(self.env, name)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\gym\core.py:229, in Wrapper.getattr(self, name)
227 if name.startswith("_"):
228 raise AttributeError(f"attempted to get missing private attribute '{name}'")
--> 229 return getattr(self.env, name)
AttributeError: 'SuperMarioBrosEnv' object has no attribute 'render_mode'
Checklist
The text was updated successfully, but these errors were encountered: