Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting " AttributeError: 'ImageData' object has no attribute 'data' " in headless gym jupyter Python 2.7

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.

like image 400
Loganathan Avatar asked Oct 26 '25 10:10

Loganathan


1 Answers

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

like image 100
David Avatar answered Oct 28 '25 23:10

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!