9

我试图让下面的代码工作。

import gym

env = gym.make("CartPole-v0")

env.reset()

env.render()

我运行前 3 行没有问题,但是当我运行第 4 行时出现错误:

Traceback (most recent call last):

  File "<ipython-input-3-a692a1a1ffe7>", line 1, in <module>
    env.render()

  File "/home/mikedoho/gym/gym/core.py", line 150, in render
    return self._render(mode=mode, close=close)

  File "/home/mikedoho/gym/gym/core.py", line 286, in _render
    return self.env.render(mode, close)

  File "/home/mikedoho/gym/gym/core.py", line 150, in render
    return self._render(mode=mode, close=close)

  File "/home/mikedoho/gym/gym/envs/classic_control/cartpole.py", line 116, in _render
    self.viewer = rendering.Viewer(screen_width, screen_height)

  File "/home/mikedoho/gym/gym/envs/classic_control/rendering.py", line 51, in __init__
    self.window = pyglet.window.Window(width=width, height=height, display=display)

  File "/home/mikedoho/anaconda3/lib/python3.6/site-packages/pyglet/window/__init__.py", line 504, in __init__
    screen = display.get_default_screen()

  File "/home/mikedoho/anaconda3/lib/python3.6/site-packages/pyglet/canvas/base.py", line 73, in get_default_screen
    return self.get_screens()[0]

  File "/home/mikedoho/anaconda3/lib/python3.6/site-packages/pyglet/canvas/base.py", line 65, in get_screens
    raise NotImplementedError('abstract')

NotImplementedError: abstract

我希望能在杆子上放一辆手推车,以便在新窗口中展示。

此错误来自 Spyder 中的代码。我正在使用 ubuntu 16.04;蟒蛇3.6.3;IPython 6.1.0。我没有使用 jupyter notebook 的运气。

我再次道歉。我对今天刚刚下载的 ubuntu 很陌生。

4

1 回答 1

15

I just resolved this (bug?), like 10 minutes ago :D

You have to downgrade pyglet 3 to pyglet 1.2.4. just type: pip install pyglet==1.2.4 in your anaconda prompt. Afterwards you might have to restart your spyder ide.

I would add env.close() to your code, otherwise you will have troubles closing the window.

if you are new to python/ML/DL have a look at "sentdex" on youtube. imo very good content to start with. (he uses TFlearn in his gym tutorial) But since tensorflow 1.4 has Keras included, i would suggest to use keras high lvl API for your neural network.

good luck and stay deep

if someone has a good gym documentation, feel free to share it.

于 2017-12-03T19:05:36.330 回答