在导入、qtopengl、pyqtgraph和designer版本兼容性方面,我遇到了问题。根据包安装的不同,设计器将不使用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会得到以下结果:
from ..Qt import QtCore, QtGui, QtOpenGL, USE_PYQT5
ImportError: cannot import name 'QtOpenGL'安装pip3 pyqt5包时,运行基本的pyqtgraph是成功的。但是,设计器无法用以下内容加载自定义小部件插件:
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来自pyqt图,但是错误只是在导入(到目前为止),所以pyqtgraph可能不是问题的来源。将对此进行进一步实验。
尝试GLViewWidget的代码
from pyqtgraph import opengl as gl, mkQApp # fails here
app = mkQApp()
view = gl.GLViewWidget()
view.show()
app.exec()designer插件最小示例(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=. designerGL如何失败:
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)发布于 2019-10-31 02:25:23
这适用于"ImportError:无法导入名称'QtOpenGL'“
sudo apt-get install python3-pyqt4.qtopengl请参阅:Just installed QtOpenGL but cannot import it (from Python)
https://stackoverflow.com/questions/56574060
复制相似问题