导入错误:找不到库“GLU”

新手上路,请多包涵

在CentOS 7.5系统上,运行python3,执行以下代码:

 import gym
import time
env = gym.make('CartPole-v0')
observation = env.reset()
count = 0
for t in range(100):
    action = env.action_space.sample()
    observation, reward, done, info = env.step(action)
    if done:
        break
    env.render()
    count+=1
    time.sleep(0.2)

执行以上代码后报如下错误:

 Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
  File "/root/gym/gym/core.py", line 284, in render
    return self.env.render(mode)
  File "/root/gym/gym/envs/classic_control/cartpole.py", line 106, in render
    from gym.envs.classic_control import rendering
  File "/root/gym/gym/envs/classic_control/rendering.py", line 25, in <module>
    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>'")
  File "/root/gym/gym/utils/reraise.py", line 17, in reraise
    reraise_impl(e, traceback)
  File "/root/gym/gym/utils/reraise_impl_py3.py", line 4, in reraise_impl
    raise e.with_traceback(traceback) from None
  File "/root/gym/gym/envs/classic_control/rendering.py", line 23, in <module>
    from pyglet.gl import *
  File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/gl/__init__.py", line 100, in <module>
    from pyglet.gl.lib import GLException
  File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/gl/lib.py", line 143, in <module>
    from pyglet.gl.lib_glx import link_GL, link_GLU, link_GLX
  File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/gl/lib_glx.py", line 51, in <module>
    glu_lib = pyglet.lib.load_library('GLU')
  File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/lib.py", line 158, in load_library
    raise ImportError('Library "%s" not found.' % names[0])
gym.utils.reraise.ReraisedException: Error occured while running `from pyglet.gl import *`

最初的例外是:

 ImportError: Library "GLU" not found.

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>'

根据错误提示,安装OpenGL后,运行代码还是会报同样的错误。下面是安装OpenGL的过程:

 [root@devmaster ~]# yum -y install python-opengl
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: ftp.iij.ad.jp
Package PyOpenGL-3.0.1-6.el7.noarch already installed and latest version
Nothing to do
[root@devmaster ~]#

原文由 Jackon 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 996
1 个回答

对于偶然发现这个问题的人,解决方案是安装 freeglut-devel 操作系统分发包:

 # apt systems - Ubuntu, Debian
apt install freeglut-devel
# yum - Centos
yum -y install freeglut-devel

原文由 Granitosaurus 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进