openAI Gym NameError in Google Colaboratory

i saw an suitablbe answer here.

pip install pyglet==1.5.11

The Gym will normally render the display using GL, on your screen.

But Colab is run on the web as a notebook, it can’t display directly to your screen. It can only show the result through HTML.

If someone modifies the Gym to maniplulate WebGL, maybe someday. But not now.


One way to render gym environment in google colab is to use pyvirtualdisplay and store rgb frame array while running environment. Environment frames can be animated using animation feature of matplotlib and HTML function used for Ipython display module. You can find the implementation here. Make sure you install required libraries which you can find in the first cell of the colab. In case the first link for google colab doesn't work you can see this one.