介绍页面中的 OpenAI Gym 错误 运行 演示

OpenAI Gym error running demo from intro page

我安装了 OpenAI Gym 并尝试 运行 入门车杆演示 (https://gym.openai.com/docs/)。 (我 运行正在使用 Colab 笔记本。)

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

这个不学,不过应该会显示车和杆。

当我 运行 它时,我收到警告和错误。

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

错误是由 env.render() 触发的。 Traceback 的底部是

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

ImportError: Library "GL" not found.

我安装了 pyOpenGL,如下所示。

!pip install PyOpenGL PyOpenGL_accelerate

对于警告和错误,我将不胜感激。我应该安装另一个 GL 库吗?

谢谢。

Google Colab 运行 在云端。它无法将图形显示发送回您的显示器。

您可以尝试 运行使用本地 运行 时间。 https://research.google.com/colaboratory/local-runtimes.html

你明白了吗window?

如果是,则尝试添加此导入:

import time

for 循环中的这行代码:

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.