3

I tried to import gym as follow:

import gym

env = gym.make("Taxi-v3")
env.reset()
env.render()

then the compiler says that pygame was missing. So I installed pygame and rerun the code and got the error:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Input In [8], in <cell line: 5>()
      3 env = gym.make("Taxi-v3")
      4 env.reset()
----> 5 env.render()

File ~\Anaconda3\envs\pytorch\lib\site-packages\gym\core.py:329, in Wrapper.render(self, *args, **kwargs)
    325 def render(
    326     self, *args, **kwargs
    327 ) -> Optional[Union[RenderFrame, List[RenderFrame]]]:
    328     """Renders the environment."""
--> 329     return self.env.render(*args, **kwargs)

File ~\Anaconda3\envs\pytorch\lib\site-packages\gym\wrappers\order_enforcing.py:51, in OrderEnforcing.render(self, *args, **kwargs)
     46 if not self._disable_render_order_enforcing and not self._has_reset:
     47     raise ResetNeeded(
     48         "Cannot call `env.render()` before calling `env.reset()`, if this is a intended action, "
     49         "set `disable_render_order_enforcing=True` on the OrderEnforcer wrapper."
     50     )
---> 51 return self.env.render(*args, **kwargs)

File ~\Anaconda3\envs\pytorch\lib\site-packages\gym\wrappers\env_checker.py:53, in PassiveEnvChecker.render(self, *args, **kwargs)
     51 if self.checked_render is False:
     52     self.checked_render = True
---> 53     return env_render_passive_checker(self.env, *args, **kwargs)
     54 else:
     55     return self.env.render(*args, **kwargs)

File ~\Anaconda3\envs\pytorch\lib\site-packages\gym\utils\passive_env_checker.py:316, in env_render_passive_checker(env, *args, **kwargs)
    310     else:
    311         assert env.render_mode is None or env.render_mode in render_modes, (
    312             "The environment was initialized successfully however with an unsupported render mode. "
    313             f"Render mode: {env.render_mode}, modes: {render_modes}"
    314         )
--> 316 result = env.render(*args, **kwargs)
    318 # TODO: Check that the result is correct
    320 return result

File ~\Anaconda3\envs\pytorch\lib\site-packages\gym\envs\toy_text\taxi.py:284, in TaxiEnv.render(self)
    282     return self._render_text()
    283 else:  # self.render_mode in {"human", "rgb_array"}:
--> 284     return self._render_gui(self.render_mode)

File ~\Anaconda3\envs\pytorch\lib\site-packages\gym\envs\toy_text\taxi.py:302, in TaxiEnv._render_gui(self, mode)
    299     elif mode == "rgb_array":
    300         self.window = pygame.Surface(WINDOW_SIZE)
--> 302 assert (
    303     self.window is not None
    304 ), "Something went wrong with pygame. This should never happen."
    305 if self.clock is None:
    306     self.clock = pygame.time.Clock()

AssertionError: Something went wrong with pygame. This should never happen.

I have installed pygame with pip install pygame and the installation was successful as well. Please help resolving this error.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
user42493
  • 813
  • 4
  • 14
  • 34
  • 1
    Does this answer your question? [I'm getting an error with env rendering - env.render()](https://stackoverflow.com/questions/71977704/im-getting-an-error-with-env-rendering-env-render) – Animesh Sahu Sep 24 '22 at 15:31

3 Answers3

4

try doing pip stable_baselines3 For me it forced a reinstall of gym (?) and now it works. let me know if that worked for you.

starball
  • 20,030
  • 7
  • 43
  • 238
  • 1
    Please read [answer] and note well that this is **not a discussion forum**. Do not ask for feedback on answers, because this is not a place to have a threaded conversation; just offer an answer to the question. If you only have a vague idea, consider not answering. A proper answer should include enough explanation so that *other people who find the question later* can understand; it's hard to do that without confidence in the answer. – Karl Knechtel Oct 01 '22 at 23:06
  • **pip install stable_baseline3** works... – Stefano Giannini Oct 19 '22 at 13:47
2

Write your code like this ...

> import gym
> env = gym.make("Taxi-v3",render_mode='ansi')
> env.reset()
> print(env.render())
koosha
  • 21
  • 2
  • This seems to have worked. Trying to do the example for an older class and will leave notes in there as well. Can't say for sure it works yet, but executed without error and output matches expected. – Eric Kreipe Jun 20 '23 at 20:44
  • OK, I will try my best – koosha Jun 23 '23 at 17:00
0

try doing

pip install stable-baselines3[extra]

neil
  • 1
  • 1