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

心已入冬 提交于 2021-01-27 18:54:15

问题


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'

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.


回答1:


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



来源:https://stackoverflow.com/questions/56946417/getting-attributeerror-imagedata-object-has-no-attribute-data-in-headle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!