Gym: Error while running test Cart Pole code given in documentation.

Created on 18 Feb 2018  路  4Comments  路  Source: openai/gym

I was running this code on gym on my PC,
```import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample()) # take a random action

It is supposed to render a cartpole environment which takes random steps. But I just see a window pop out for a second and this error when I run this code. I can't seem to find the issue here

Exception ignored in: >
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/gym/envs/classic_control/rendering.py", line 143, in __del__
File "/usr/local/lib/python3.5/dist-packages/gym/envs/classic_control/rendering.py", line 62, in close
File "/usr/local/lib/python3.5/dist-packages/pyglet/window/xlib/__init__.py", line 480, in close
File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/xlib.py", line 345, in destroy
File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/base.py", line 334, in destroy
File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/xlib.py", line 335, in detach
File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/lib.py", line 97, in errcheck
File "", line 969, in _find_and_load
File "", line 954, in _find_and_load_unlocked
File "", line 887, in _find_spec
TypeError: 'NoneType' object is not iterable
```

Most helpful comment

Calling env.close() at the end of scripts will solve this problem.

import gym
import time
env = gym.make('Pong-v0')
env.reset()

env.render()
env.step(env.action_space.sample())

env.close()

All 4 comments

I'm having the same problem. I guess it running so fast because when i've print out the iteration. But the error still the myth and I cannot understand why I have that "running so fast". My laptop use Ubuntu 16.04, NVIDIA GTX 950M. I followed the link, tried adding import time and time.sleep(0.05) to slow down the program, It's easier to watch the animation :|

Calling env.close() at the end of scripts will solve this problem.

import gym
import time
env = gym.make('Pong-v0')
env.reset()

env.render()
env.step(env.action_space.sample())

env.close()

With me, it does not work!

Thank you, LianYun. It worked for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Spiral-Galaxy picture Spiral-Galaxy  路  3Comments

julian-ramos picture julian-ramos  路  4Comments

mdavis-xyz picture mdavis-xyz  路  3Comments

RuofanKong picture RuofanKong  路  4Comments

tylerlekang picture tylerlekang  路  3Comments