4

I am trying to run gym in headless server and render the same in jupyter. Python version 2.7.

I have started the jupyter using xvfb-run -a -s "-screen 0 1400x900x24" jupyter notebook

Below is the Jupyte cell that I run.

import matplotlib.pyplot as plt
import gym
from IPython import display
%matplotlib inline

env = gym.make('CartPole-v0')
env.reset()

plt.imshow(env.render(mode='rgb_array'))
display.display(plt.gcf())    
display.clear_output(wait=True)
env.step(env.action_space.sample()) # take a random action

env.close()

But the error I get is as below :

AttributeError: 'ImageData' object has no attribute 'data'

enter image description here

I have searched a lot in forums but could not find a solution. Thanks in advance to help me fix this error and make me to render gym in jupyter notebook.

patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
Loganathan
  • 903
  • 2
  • 10
  • 23
  • After some time I have chosen to go with Python 3 and used below link for the jupyter setup. And it worked. https://www.digitalocean.com/community/tutorials/how-to-set-up-jupyter-notebook-with-python-3-on-ubuntu-18-04 – Loganathan Jul 09 '19 at 12:31

3 Answers3

6

I encountered the same issue. Installing pyglet-v1.3.2 instead of v1.4.1 solved the issue for me.

David
  • 1,660
  • 3
  • 21
  • 33
0

I have python 3.7 and for my upgrading to gym 0.18.2 solved the problem (with pyglet 1.5.5)

patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
0

For what it's worth, like @patapouf_ai I upgraded from gym 0.9.6 to gym 0.19.0 and this solved the problem. It seems the root issue is that mode=rgb_mode returned error when passed into env.render.

Stan Lin
  • 928
  • 7
  • 6