Official pytorch RL tutorial notebook is broken for me can some one else confirm?

Just downloaded the jupyter notebook for deep Q-learning and I would get error for the code block that is suppose to extract and process the rendered images from the environment.

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-7-db314a5502f8> in <module>()
     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')

<ipython-input-7-db314a5502f8> in get_screen()
     14 
     15 def get_screen():
---> 16     screen = env.render(mode='rgb_array').transpose(
     17         (2, 0, 1))  # transpose into torch order (CHW)
     18     # Strip off the top and bottom of the screen

C:\Anaconda3\lib\site-packages\gym\envs\classic_control\cartpole.py in render(self, mode)
    105         if self.viewer is None:
    106             from gym.envs.classic_control import rendering
--> 107             self.viewer = rendering.Viewer(screen_width, screen_height)
    108             l,r,t,b = -cartwidth/2, cartwidth/2, cartheight/2, -cartheight/2
    109             axleoffset =cartheight/4.0

C:\Anaconda3\lib\site-packages\gym\envs\classic_control\rendering.py in __init__(self, width, height, display)
     49         self.width = width
     50         self.height = height
---> 51         self.window = pyglet.window.Window(width=width, height=height, display=display)
     52         self.window.on_close = self.window_closed_by_user
     53         self.isopen = True

C:\Anaconda3\lib\site-packages\pyglet\window\__init__.py in __init__(self, width, height, caption, resizable, style, fullscreen, visible, vsync, display, screen, config, context, mode)
    502 
    503         if not screen:
--> 504             screen = display.get_default_screen()
    505 
    506         if not config:

C:\Anaconda3\lib\site-packages\pyglet\canvas\base.py in get_default_screen(self)
     71         :rtype: :class:`Screen`
     72         '''
---> 73         return self.get_screens()[0]
     74 
     75     def get_windows(self):

C:\Anaconda3\lib\site-packages\pyglet\canvas\base.py in get_screens(self)
     63         :rtype: list of :class:`Screen`
     64         '''
---> 65         raise NotImplementedError('abstract')
     66 
     67     def get_default_screen(self):

NotImplementedError: abstract

<matplotlib.figure.Figure at 0x202fd020278>

I am not sure what I need to do can some one please help?

Link to the tutorial where you can download the notebook.

https://pytorch.org/tutorials/intermediate/reinforcement_q_learning.html#sphx-glr-download-intermediate-reinforcement-q-learning-py

This is the issue and how to fix it. If you don’t want to read the thread the issue is caused by pyglet not playing nice with jupyternotebook. You either have to downgrade to 1.2.4 or do this:

after some checking.
python3.6/site-packages/pyglet/__init__.py

change

 if 'sphinx' in sys.modules:
    setattr(sys, 'is_epydoc', True)
to

if 'sphinx' in sys.modules:
    setattr(sys, 'is_epydoc', False)

pyglet has problem with jupyter, jupyter imports sphinx be default
but sphinx imported will lead pyglet thinks it is generating document? so cannot find display correctly.

https://github.com/openai/gym/issues/775

1 Like