微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

执行使用gym库进行强化学习的python文件时出错

如何解决执行使用gym库进行强化学习的python文件时出错

我的python程序:

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
env.close()

我看到的错误

(base) Meets-MacBook-Pro:Documents meetpandya$ python gym-test.py
Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.8/site-packages/gym/envs/classic_control/rendering.py",line 25,in <module>
    from pyglet.gl import *
  File "/opt/anaconda3/lib/python3.8/site-packages/pyglet/gl/__init__.py",line 95,in <module>
    from pyglet.gl.lib import GLException
  File "/opt/anaconda3/lib/python3.8/site-packages/pyglet/gl/lib.py",line 147,in <module>
    from pyglet.gl.lib_agl import link_GL,link_glu,link_AGL
  File "/opt/anaconda3/lib/python3.8/site-packages/pyglet/gl/lib_agl.py",line 43,in <module>
    gl_lib = pyglet.lib.load_library(framework='/System/Library/Frameworks/OpenGL.framework')
  File "/opt/anaconda3/lib/python3.8/site-packages/pyglet/lib.py",line 124,in load_library
    return self.load_framework(kwargs['framework'])
  File "/opt/anaconda3/lib/python3.8/site-packages/pyglet/lib.py",line 279,in load_framework
    raise ImportError("Can't find framework %s." % path)
ImportError: Can't find framework /System/Library/Frameworks/OpenGL.framework.

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "gym-test.py",line 5,in <module>
    env.render()
  File "/opt/anaconda3/lib/python3.8/site-packages/gym/core.py",line 240,in render
    return self.env.render(mode,**kwargs)
  File "/opt/anaconda3/lib/python3.8/site-packages/gym/envs/classic_control/cartpole.py",line 174,in render
    from gym.envs.classic_control import rendering
  File "/opt/anaconda3/lib/python3.8/site-packages/gym/envs/classic_control/rendering.py",line 27,in <module>
    raise ImportError('''
ImportError: 
    Error occurred while running `from pyglet.gl import *`
    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>'

我已经在我的笔记本电脑上成功安装了健身房库。我不明白“查找框架/System/Library/Frameworks/OpenGL.framework”的含义。

解决方法

试试这个,按照这个thread

您将收到错误 gym 0.17.3 requires pyglet<=1.5.0,>=1.4.0,but you'll have pyglet 1.5.11 which is incompatible,但代码现在应该可以工作了。

pip install pyglet==1.5.11

编辑:

现在应该可以了

pip install --user --upgrade git+http://github.com/pyglet/pyglet@pyglet-1.5-maintenance

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。