pyqtgraph 的 OpenGL 导入失败

Posted

技术标签:

【中文标题】pyqtgraph 的 OpenGL 导入失败【英文标题】:OpenGL import fails with pyqtgraph 【发布时间】:2021-05-08 10:00:15 【问题描述】:

我有一个安装了 python 3、pyopengl 和 pyqtgraph 的 conda 环境。运行 import OpenGL 没有问题,但是当我尝试使用 python -m pyqtgraph.examples 运行 pyqtgraph 示例时,大多数示例都有效,但如果我运行需要 OpenGL 的 3D 示例之一,我会收到以下错误:

Using PyQt5 (default graphics system)
Traceback (most recent call last):
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 35, in GL
    return ctypesloader.loadLibrary(
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/ctypesloader.py", line 45, in loadLibrary
    return dllType( name, mode )
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/ctypes/__init__.py", line 381, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: ('dlopen(OpenGL, 10): image not found', 'OpenGL', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/pyqtgraph/examples/GLIsosurface.py", line 12, in <module>
    import pyqtgraph.opengl as gl
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/pyqtgraph/opengl/__init__.py", line 1, in <module>
    from .GLViewWidget import GLViewWidget
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/pyqtgraph/opengl/GLViewWidget.py", line 2, in <module>
    from OpenGL.GL import *
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
    from OpenGL import error as _error
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/error.py", line 12, in <module>
    from OpenGL import platform, _configflags
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/__init__.py", line 35, in <module>
    _load()
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/__init__.py", line 32, in _load
    plugin.install(globals())
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 92, in install
    namespace[ name ] = getattr(self,name,None)
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 14, in __get__
    value = self.fget( obj )
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 62, in GetCurrentContext
    return self.CGL.CGLGetCurrentContext 
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 14, in __get__
    value = self.fget( obj )
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 45, in CGL
    def CGL(self): return self.GL
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 14, in __get__
    value = self.fget( obj )
  File "/usr/local/Caskroom/miniconda/base/envs/mcdermott3/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 41, in GL
    raise ImportError("Unable to load OpenGL library", *err.args)
ImportError: ('Unable to load OpenGL library', 'dlopen(OpenGL, 10): image not found', 'OpenGL', None)

任何想法如何解决这个问题?如果相关,我将在 Mac OS Big Sur 中运行它并使用 conda 安装所有内容。

编辑:我刚刚发现 this 有一个类似的问题,但仍然不知道该怎么办。

【问题讨论】:

【参考方案1】:

来自与 Paul McCarthy 的电子邮件:

“这可能是由于 Big Sur 的更改影响了 Python 查找共享库的方式,导致 PyOpenGL 中断,实际上与您发现的 FSLeyes github 问题无关。Big Sur 现在从文件系统,而是将它们放入内存缓存中。然后它拦截引用完整文件路径的 dlopen 调用,并从缓存中加载文件。这与 Python 以前用于加载共享库的方法不兼容在 macOS 上。Python 人员已经实现了一个解决方案,但我不确定修复程序是否已经发布(我认为它只针对 Python 3.8 及更高版本发布)。”

This 链接对此问题进行了一些修复。

【讨论】:

以上是关于pyqtgraph 的 OpenGL 导入失败的主要内容,如果未能解决你的问题,请参考以下文章

pyqtgraph QGraphicsWidget 导入错误

PyQtGraph & OpenGL:如何在两个坐标之间创建一个球体?

PyQtGraph 崩溃 python

OpenGL 中的 FBX SDK 导入器和 LH 坐标系统

无法使用 OpenGL 渲染 FBX 导入的纹理模型

opengl导入一个3维物体,如何修改其局部坐标系?