How do i display the super mario environment on google colab

Viewed 296
 done = True
    
    
    for step in range(100000):
    
     
      if done:
    
       
        env.reset()
    
     
      state, reward, done, info = env.step(env.action_space.sample())
      env.render()
    env.close()

when run this code i get this error

    AttributeError        Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pyglet/__init__.py in __getattr__(self, name)
    328         try:
--> 329             return getattr(self._module, name)
    330         except AttributeError:

AttributeError: 'NoneType' object has no attribute 'key'

During handling of the above exception, another exception occurred:

NoSuchDisplayException                    Traceback (most recent call last)
11 frames
/usr/local/lib/python3.7/dist-packages/pyglet/canvas/xlib.py in __init__(self, name, x_screen)
    121         self._display = xlib.XOpenDisplay(name)
    122         if not self._display:
--> 123             raise NoSuchDisplayException('Cannot connect to "%s"' % name)
    124 
    125         screen_count = xlib.XScreenCount(self._display)

NoSuchDisplayException: Cannot connect to "None"

how do i display the other screen that displays the game i have tried using matplotlib along with all the necc. imports but its very slow and take a long time to complete the above steps so i had to reduce it to 5000 but still it took a long time in this youtube video this person doesnt install and extra packages and the rendering screen appears how do i do that? if its not possible on colab then how do i do it on jupyter notebook. this link

Setup a Mario Environment Preprocess Mario for Applied Reinforcement Learning Build a Reinforcement Learning model to play Mario Take a look at the final results

1 Answers

Common practice when using gym on collab and wanting to watch videos of episodes you save them as mp4s, as there is no attached video device (and has benefit of allowing you to watch back at any time during the session).

You do this by wrapping your environment with the Monitor wrapper.

If this is during training for example you could save every 100 episodes using the following code:


video_every = 100
env = gym.wrappers.Monitor(env, "./video", video_callable=lambda episode_id: (episode_id%video_every)==0, force=True)

done = True
for step in range(100000):
    if done:
        env.reset()
    state, reward, done, info = env.step(env.action_space.sample())
env.close()

This saves a video of every video_every'th episode to the folder "video" (which you can access from the bar on the left of colab)

Related