1 问题描述
在 pip install pyrender
成功安装后,调用pyrender
库时报错:
OSError: (‘GL: cannot open shared object file: No such file or directory’, ‘GL’, None)
ImportError: (‘Unable to load OpenGL library’, ‘GL: cannot open shared object file: No such file or directory’, ‘GL’, None)
报错截图:
2 原因分析
这种问题一般会出现在本机/docker环境中,我这个错误发生在(基本上发生在linux系统中,windows一般都不会出现):
Ubuntu18.04
Python3.9
anaconda base
报错信息聚焦在:No such file or directory', 'GL'
。也就是当前环境中缺少GL库文件,是GL库有问题,所以导致pyrender
不能正常运行,这也解释了为什么pip install pyrender
可以正常安装,但是pyrender
却运行不了。
3 解决方法
既然是GL库文件缺失导致的这个问题,那就需要在当前系统中重新安装GL库文件。具体操作流程:
3.1 更新apt
apt-get update
这一步非常重要,一般出现这种问题都是说明当前linux系统存在问题,因此当前的源也有极大概率是坏的,所以一定要确保更新到最新的源再进行下一步。
apt更新过程:
3.2 安装GL库
执行:
apt install libgl1-mesa-glx
![](https://img-blog.csdnimg.cn/direct/3b5b7ee2cb564f7c891fb79e568111c5.png#pic_center)
3.3 测试是否解决
完成安装后,打开python
导入pyrender
,检查是否可以正确导入。
![](https://img-blog.csdnimg.cn/direct/fc869998fee9437ab8cd20f0a01a6dd1.png#pic_center)
如图所示,现在已经可以正确导入pyrender
库。