I am trying to learn Q-Learning by using OpenAI's gym module. But when I try to render my environment, I get the following error,
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
I get the same error when I run my code from the command prompt
Also, here is my code,
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()
I was not able to find this error on the internet with gym, so I am not able to solve it. I even tried the cartpole environment but ended with the same error.
Any help is appreciated.