【发布时间】:2019-10-16 22:25:45
【问题描述】:
我正在尝试使用 OpenAI 的健身房模块来学习 Q-Learning。但是当我尝试渲染我的环境时,我收到以下错误,
OSError Traceback (most recent call last)
<ipython-input-1-c269c1129a2f> in <module>
12 action = 2
13 new_state, reward, done, _ = env.step(action)
---> 14 plt.imshow(env.render(mode='rgb_array'))
15 disp
16
C:\Program Files\Python37\lib\site-packages\gym\core.py in render(self, mode, **kwargs)
228
229 def render(self, mode='human', **kwargs):
--> 230 return self.env.render(mode, **kwargs)
231
232 def close(self):
C:\Program Files\Python37\lib\site-packages\gym\envs\classic_control\mountain_car.py in render(self, mode)
116 self.cartrans.set_rotation(math.cos(3 * pos))
117
--> 118 return self.viewer.render(return_rgb_array = mode=='rgb_array')
119
120 def get_keys_to_action(self):
C:\Program Files\Python37\lib\site-packages\gym\envs\classic_control\rendering.py in render(self, return_rgb_array)
112 arr = arr.reshape(buffer.height, buffer.width, 4)
113 arr = arr[::-1,:,0:3]
--> 114 self.window.flip()
115 self.onetime_geoms = []
116 return arr if return_rgb_array else self.isopen
C:\Program Files\Python37\lib\site-packages\pyglet\window\win32\__init__.py in flip(self)
319 def flip(self):
320 self.draw_mouse_cursor()
--> 321 self.context.flip()
322
323 def set_location(self, x, y):
C:\Program Files\Python37\lib\site-packages\pyglet\gl\win32.py in flip(self)
224
225 def flip(self):
--> 226 _gdi32.SwapBuffers(self.canvas.hdc)
227
228 def get_vsync(self):
OSError: exception: access violation reading 0x000000000000001C
当我从命令提示符运行我的代码时,我得到了同样的错误
另外,这是我的代码,
import matplotlib.pyplot as plt
import gym
from IPython import display
%matplotlib inline
env = gym.make("MountainCar-v0")
env.reset()
done = False
while not done:
action = 2
new_state, reward, done, _ = env.step(action)
plt.imshow(env.render(mode='rgb_array'))
display.display(plt.gcf())
display.clear_output(wait=True)
env.close()
我无法通过健身房在互联网上找到此错误,因此无法解决。 我什至尝试了 cartpole 环境,但以同样的错误结束。
感谢任何帮助。
【问题讨论】:
标签: python python-3.x pyglet openai-gym q-learning