当前位置: 首页 > 工具软件 > glu > 使用案例 >

【解决方案】解决ImportError: Library “GLU“ not found.问题

林铭
2023-12-01

1.背景介绍

今天使用租的云服务器跑强化学习代码,遇到了问题ImportError: Library “GLU” not found。

Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.8/site-packages/gym/envs/classic_control/rendering.py", line 27, in <module>
    from pyglet.gl import *
  File "/root/miniconda3/lib/python3.8/site-packages/pyglet/gl/__init__.py", line 95, in <module>
    from pyglet.gl.gl import *
  File "/root/miniconda3/lib/python3.8/site-packages/pyglet/gl/gl.py", line 45, in <module>
    from pyglet.gl.lib import link_GL as _link_function
  File "/root/miniconda3/lib/python3.8/site-packages/pyglet/gl/lib.py", line 149, in <module>
    from pyglet.gl.lib_glx import link_GL, link_GLU, link_GLX
  File "/root/miniconda3/lib/python3.8/site-packages/pyglet/gl/lib_glx.py", line 46, in <module>
    glu_lib = pyglet.lib.load_library('GLU')
  File "/root/miniconda3/lib/python3.8/site-packages/pyglet/lib.py", line 168, in load_library
    raise ImportError('Library "%s" not found.' % names[0])
ImportError: Library "GLU" not found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "TrainMaze.py", line 2, in <module>
    from MazeEnv import Maze
  File "/home/my-mcpg/MazeEnv.py", line 5, in <module>
    from gym.envs.classic_control import rendering
  File "/root/miniconda3/lib/python3.8/site-packages/gym/envs/classic_control/rendering.py", line 29, in <module>
    raise ImportError(
ImportError:
    Error occurred while running `from pyglet.gl import *`
    HINT: make sure you have OpenGL installed. 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>'

2.解决方案

报错提示中有一个提示信息:

HINT: make sure you have OpenGL installed. On Ubuntu, you can run 'apt-get install python-opengl'.

意思就是说确保安装了OpenGL库,在Ubuntu中,可以通过apt-get install python-opengl命令来安装。所以,操作如下:

apt-get install python-opengl

但使用上述命令时又遇到了一个其他问题:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-opengl

解决方案:使用sudo权限,更新apt-get。

sudo apt-get update

重新安装python-opengl即可

apt-get install python-opengl
 类似资料: