Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'SuperMarioBrosEnv' object has no attribute 'render_mode' #1532

Closed
4 tasks done
Asjad22 opened this issue May 30, 2023 · 5 comments
Closed
4 tasks done
Labels
custom gym env Issue related to Custom Gym Env more information needed Please fill the issue template completely

Comments

@Asjad22
Copy link

Asjad22 commented May 30, 2023

❓ 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)

[... skipping similar frames: Wrapper.__getattr__ at line 229 (1 times)]

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

  • I have checked that there is no similar issue in the repo
  • I have read the documentation
  • If code there is, it is minimal and working
  • If code there is, it is formatted using the markdown code blocks for both code and stack traces.
@Asjad22 Asjad22 added the question Further information is requested label May 30, 2023
@qgallouedec
Copy link
Collaborator

It seems like you're using a custom env. So, please fill the custom env issue template completely.

  • If code there is, it is formatted using the markdown code blocks for both code and stack traces.

Also, please check that you have completed the item before checking a box.

@qgallouedec qgallouedec added custom gym env Issue related to Custom Gym Env more information needed Please fill the issue template completely and removed question Further information is requested labels May 30, 2023
@Asjad22
Copy link
Author

Asjad22 commented May 31, 2023

I'm new to this and I really didn't get it.
Im using virtual environment with python3.11. I saw a tutorial on the web I followed along.

@araffin
Copy link
Member

araffin commented Jun 15, 2023

Closing as the issue template was not filled properly, also seems to be related to a custom env, not SB3.

@araffin araffin closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2023
@NUSShao
Copy link

NUSShao commented Aug 11, 2023

Bro I just solved this problem by reinstalling an old version of stable-baselines3.
You can try: pip install stable-baselines3[extra]==1.4.0

@fanshuaiyao
Copy link

pip install stable-baselines3[extra]==1.4.0

very good bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom gym env Issue related to Custom Gym Env more information needed Please fill the issue template completely
Projects
None yet
Development

No branches or pull requests

5 participants