在无头gym jupyter Python 2.7中出现“AttributeError: 'ImageData'对象没有属性'data'”

4
我正在尝试在无头服务器上运行gym,并在jupyter中呈现相同的内容。 Python版本为2.7。
我使用以下命令启动了jupyter:xvfb-run -a -s "-screen 0 1400x900x24" jupyter notebook 以下是我运行的Jupyter单元格。
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()

但我收到的错误如下:
AttributeError: 'ImageData' object has no attribute 'data'

enter image description here

我在论坛中搜索了很多,但是没有找到解决方案。提前感谢您帮助我修复此错误并使我能够在jupyter笔记本中呈现gym。


经过一段时间的考虑,我决定使用Python 3,并使用以下链接进行jupyter设置。结果很成功。 https://www.digitalocean.com/community/tutorials/how-to-set-up-jupyter-notebook-with-python-3-on-ubuntu-18-04 - Loganathan
3个回答

6
我遇到了相同的问题。安装pyglet-v1.3.2而不是v1.4.1为我解决了这个问题。

谢谢你的答复!但是,尽管应用了你提供的解决方案,我仍无法让它正常工作。错误依旧。不过,我已经切换到Python 3,所以对此问题不再担心。 - Loganathan
1
@Loganathan 我明白了。很高兴你搞定了! - David
我有Python 3,但这个解决方案对我无效。 - patapouf_ai

0

我有 Python 3.7,升级到 Gym 0.18.2 解决了我的问题(使用 Pyglet 1.5.5


0

值得一提的是,像@patapouf_ai一样,我从gym 0.9.6升级到gym 0.19.0,这解决了问题。似乎根本问题是当传递到env.render时mode=rgb_mode返回错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接