RussAbbott
RussAbbott

Reputation: 2738

OpenAI Gym error running demo from intro page

I installed OpenAI Gym and attempted to run the getting-started cart-pole demo (https://gym.openai.com/docs/). (I'm running in a Colab notebook.)

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

This doesn't learn, but it should display the cart and pole.

When I run it I get a warning and an error.

WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype.

The error is triggered by env.render(). At the bottom of the Traceback is

Error occured while running `from pyglet.gl import *`
The original exception was:

ImportError: Library "GL" not found.

I had installed pyOpenGL with the following.

!pip install PyOpenGL PyOpenGL_accelerate

I'd appreciate help with both the warning and the error. Is there another GL library I should install?

Thanks.

Upvotes: 1

Views: 1130

Answers (2)

mrk
mrk

Reputation: 10366

Do you get this window?

window

If yes then try to add this import:

import time

and this line of Code within the for-loop:

time.sleep(0.3)

Thing is that the pole runs out of view rather quick, so it seems like the Environment did not run at all.

Upvotes: 0

korakot
korakot

Reputation: 40828

Google Colab is run in the cloud. It can't send the graphic display back to your monitor.

You can try running it with local runtime. https://research.google.com/colaboratory/local-runtimes.html

Upvotes: 1

Related Questions