[PyQt5安装导致设计器出现qtopengl,可能是pyqtgraph错误

问题描述 投票:0回答:1

我在导入,qtopengl,pyqtgraph和设计器版本兼容性方面遇到问题。根据软件包安装的不同,设计人员要么不会加载带有libQt5Core.so ImportError的自定义插件,要么GLViewWidgets会由于QtOpenGl ImportError而失败。

我的问题:

  • 是否存在兼容性问题?
  • 版本有问题吗?
  • 以前有人解决过这些问题吗?我不确定是否或如何连接。
  • 是否有办法使两种情况同时工作?

安装:(python3.6,ubuntu 18.04)

pip3 install --user pyqt5  # -> PyQt5-5.12.2
pip3 install --user pyqtgraph  # -> 0.10.0
apt-get install python3-pyqt5

未安装pip3 pyqt5软件包时,设计器将打开并成功加载自定义窗口小部件插件。但是,运行基本的pyqtgraph GLViewWidget会导致:

from ..Qt import QtCore, QtGui, QtOpenGL, USE_PYQT5
ImportError: cannot import name 'QtOpenGL'

安装了pip3 pyqt5软件包后,成功运行基本pyqtgraph GLViewWidget。但是设计器无法通过以下方式加载自定义小部件插件:

from PyQt5 import QtWidgets, QtCore
ImportError: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.12' not found (required by /home/USER/.local/lib/python3.6/site-packages/PyQt5/QtWidgets.so)

注意:自定义窗口小部件插件与GLViewWidget完全无关,而GLViewWidget与设计器完全无关。GLViewWidget来自pyqtgraph,但是错误仅在导入时(到目前为止),因此pyqtgraph可能不是问题的根源。将对此做进一步的试验。


尝试GLViewWidget的代码

from pyqtgraph import opengl as gl, mkQApp  # fails here
app = mkQApp()
view = gl.GLViewWidget()
view.show()
app.exec()

设计器插件最小示例(QVLabel_plugin.py)

from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtDesigner import QPyDesignerCustomWidgetPlugin

class QVLabel(QtWidgets.QLabel):
    pass

class QVLabelPlugin(QPyDesignerCustomWidgetPlugin):
        def __init__(self, parent=None):
            QPyDesignerCustomWidgetPlugin.__init__(self)
            self.initialized = False
        def initialize(self, formEditor):
            if self.initialized:
                return
            self.initialized = True
        def isInitialized(self):
            return self.initialized
        def createWidget(self, parent):
            return QVLabel(parent=parent)
        def name(self):
            return "QVLabel"
        def group(self):
            return "Custom Widgets"
        def icon(self):
            return None  # will raise TypeError in designer, but everything should work fine
        def toolTip(self):
            return ''
        def whatsThis(self):
            return ''
        def isContainer(self):
            return True
        def includeFile(self):
            return "QVLabel_plugin"

QVLabel_plugin.py目录中的运行设计器

PYQTDESIGNERPATH=. designer

GL如何失败:

from ..Qt import QtCore, QtGui, QtOpenGL, USE_PYQT5
ImportError: cannot import name 'QtOpenGL'

设计者如何失败:

from PyQt5 import QtWidgets, QtCore
ImportError: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.12' not found (required by /home/USER/.local/lib/python3.6/site-packages/PyQt5/QtWidgets.so)
pyqt5 python-3.6 importerror qt-designer pyqtgraph
1个回答
0
投票

这适用于“ ImportError:无法导入名称'QtOpenGL'”]

sudo apt-get install python3-pyqt4.qtopengl

请参阅:Just installed QtOpenGL but cannot import it (from Python)

© www.soinside.com 2019 - 2024. All rights reserved.