我刚刚在Google Colab上安装了openAI健身房,但是当我尝试以explained here的方式运行‘CartPole-v0’环境时。
代码:
import gym
env = gym.make('CartPole-v0')
for i_episode in range(20):
observation = env.reset()
for t in range(100):
env.render()
print(observation)
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
我明白了:
WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype.
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-19-a81cbed23ce4> in <module>()
4 observation = env.reset()
5 for t in range(100):
----> 6 env.render()
7 print(observation)
8 action = env.action_space.sample()
/content/gym/gym/core.py in render(self, mode)
282
283 def render(self, mode='human'):
--> 284 return self.env.render(mode)
285
286 def close(self):
/content/gym/gym/envs/classic_control/cartpole.py in render(self, mode)
104
105 if self.viewer is None:
--> 106 from gym.envs.classic_control import rendering
107 self.viewer = rendering.Viewer(screen_width, screen_height)
108 l,r,t,b = -cartwidth/2, cartwidth/2, cartheight/2, -cartheight/2
/content/gym/gym/envs/classic_control/rendering.py in <module>()
21
22 try:
---> 23 from pyglet.gl import *
24 except ImportError as e:
25 reraise(prefix="Error occured while running `from pyglet.gl import *`",suffix="HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'. If you're running on a server, you may need a virtual frame buffer; something like this should work: 'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'")
/usr/local/lib/python3.6/dist-packages/pyglet/gl/__init__.py in <module>()
225 else:
226 from .carbon import CarbonConfig as Config
--> 227 del base
228
229 # XXX remove
NameError: name 'base' is not defined
问题在this question about NameError in openAI gym中是相同的
没有渲染任何内容。我不知道如何在google colab中使用这个:'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'"
哈维尔,你能找到解决这个问题的办法吗?我试图使用OenAIs的新环境“健身房复古”,并得到同样的错误时,调用make。但正如您所说,我认为使用xvfb应该可以解决这个问题并让程序运行,但当然我们无法以图形方式查看环境。但问题是不允许xvfb在后台运行!xvfb:99&;引发OSError:不支持后台进程。
健身房通常会在屏幕上使用GL渲染显示。
但是Colab是作为笔记本在网络上运行的,它不能直接显示在你的屏幕上。它只能通过HTML显示结果。
如果有人把健身房改成maniplulate WebGL,也许有一天。但现在不行。
在google colab中渲染健身房环境的一种方法是在运行环境时使用pyvirtualdisplay并存储rgb帧数组。可以使用matplotlib的动画功能和Ipython显示模块使用的HTML函数设置环境帧的动画。 您可以找到实现here。 确保安装了所需的库,这些库可以在colab的第一个单元格中找到。如果google colab的第一个链接不起作用,您可以看到this one。
相关问题 更多 >
编程相关推荐