TUTORIAL DQN example: NoSuchDisplayException in Colab

I try to run “REINFORCEMENT LEARNING (DQN) TUTORIAL” in Colab and get a NoSuchDisplayException: Cannot connect to “None”.

plt.imshow(get_screen().cpu().squeeze(0).permute(1, 2, 0).numpy(),
plt.title(‘Example extracted screen’)

NoSuchDisplayException Traceback (most recent call last)
in ()
39 env.reset()
40 plt.figure()
—> 41 plt.imshow(get_screen().cpu().squeeze(0).permute(1, 2, 0).numpy(),
42 interpolation=‘none’)
43 plt.title(‘Example extracted screen’)

10 frames
/usr/local/lib/python3.6/dist-packages/pyglet/canvas/xlib.py in init(self, name, x_screen)
84 self._display = xlib.XOpenDisplay(name)
85 if not self._display:
—> 86 raise NoSuchDisplayException(‘Cannot connect to “%s”’ % name)
88 screen_count = xlib.XScreenCount(self._display)

NoSuchDisplayException: Cannot connect to “None”

I thought that the tutorials is adapted to the Colab, because there is even a link to launch them. What is an easy way to avoid this error? Or is it necessary to deal with pyvirtualdisplay?

1 Like

Still facing the issue. Did you find any workaround?

Add a line above your notebook to plot inline:
%matplotlib inline

source: https://colab.research.google.com/github/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/04.00-Introduction-To-Matplotlib.ipynb#scrollTo=0YPlWWlcucAx