运行示例pyqtgraph程序时出现多个错误(主要是sip类型错误)

2024-05-03 09:18:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试在pyqt5中制作一些图形,这些图形可以比当前嵌入的matplotlib图形更新得更快、更高效

每当我运行任何示例代码(包括pyqtgraph)时,都会遇到相同的问题,该示例代码总是抛出以下错误: "TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget"

环境:

Spyder 3.3.2 Python 3.7.1 64位| Qt 5.9.6 | PyQt5 5.9.2 | Windows 10。 在运行pip freeze之后,我了解到我的版本是numpy==1.20.1、PyQt5==5.15.2、pyqt5sip==12.8.1、pyqtgraph==0.11.1

我正在使用一个非常简单的测试图,它来自一个turial(Link

from PyQt5 import QtWidgets
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
import sys  # We need sys so that we can pass argv to QApplication
import os

class MainWindow(QtWidgets.QMainWindow):

    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.graphWidget = pg.PlotWidget()
        self.setCentralWidget(self.graphWidget)

        hour = [1,2,3,4,5,6,7,8,9,10]
        temperature = [30,32,34,32,33,31,29,32,35,45]

        # plot data: x, y values
        self.graphWidget.plot(hour, temperature)


def main():
    app = QtWidgets.QApplication(sys.argv)
    main = MainWindow()
    main.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

在回溯中导致最新错误的代码位于“Qt.py”中,代码如下:

# Common to PyQt4 and 5
if QT_LIB in [PYQT4, PYQT5]:
    QtVersion = QtCore.QT_VERSION_STR
    
    try:
        from PyQt5 import sip
    except ImportError:
        import sip
    def isQObjectAlive(obj):
        return not sip.isdeleted(obj)
    
    loadUiType = uic.loadUiType

    QtCore.Signal = QtCore.pyqtSignal

完整回溯要长得多,如下所示:

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
    ret = sip.cast(ret, QtGui.QGraphicsItem)

TypeError: cast() argument 1 must be sip.simplewrapper, not PlotItem

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 438, in resizeEvent
    self.updateAutoRange()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 890, in updateAutoRange
    childRange = self.childrenBounds(frac=fractionVisible)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 1355, in childrenBounds
    px, py = [v.length() if v is not None else 0 for v in self.childGroup.pixelVectors()]

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 189, in pixelVectors
    dt = self.deviceTransform()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 108, in deviceTransform
    view = self.getViewWidget()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 65, in getViewWidget
    if v is not None and not isQObjectAlive(v):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\Qt.py", line 328, in isQObjectAlive
    return not sip.isdeleted(obj)

TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
    ret = sip.cast(ret, QtGui.QGraphicsItem)

TypeError: cast() argument 1 must be sip.simplewrapper, not PlotDataItem

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
    ret = sip.cast(ret, QtGui.QGraphicsItem)

TypeError: cast() argument 1 must be sip.simplewrapper, not PlotDataItem

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 26, in itemChange
    self.parentChanged()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 463, in parentChanged
    self._updateView()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 480, in _updateView
    view = self.getViewBox()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 88, in getViewBox
    vb = self.getViewWidget()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 65, in getViewWidget
    if v is not None and not isQObjectAlive(v):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\Qt.py", line 328, in isQObjectAlive
    return not sip.isdeleted(obj)

TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsObject.py", line 40, in itemChange
    ret = sip.cast(ret, QtGui.QGraphicsItem)

TypeError: cast() argument 1 must be sip.simplewrapper, not ChildGroup

Traceback (most recent call last):

  File "<ipython-input-2-5f5dea77ec5e>", line 1, in <module>
    runfile('C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py', wdir='C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py", line 30, in <module>
    main()

  File "C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py", line 24, in main
    main = MainWindow()

  File "C:/Users/dowdt/GoogleDrive/Documents/Purdue/GraduateSchool/Homologation/Software/Python Test Code/Python GUI practice/pyqt5LiveGraphExample.py", line 19, in __init__
    self.graphWidget.plot(hour, temperature)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\PlotItem\PlotItem.py", line 653, in plot
    self.addItem(item, params=params)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\PlotItem\PlotItem.py", line 530, in addItem
    self.vb.addItem(item, *args, **vbargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 409, in addItem
    self.updateAutoRange()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 890, in updateAutoRange
    childRange = self.childrenBounds(frac=fractionVisible)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 1355, in childrenBounds
    px, py = [v.length() if v is not None else 0 for v in self.childGroup.pixelVectors()]

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 189, in pixelVectors
    dt = self.deviceTransform()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 108, in deviceTransform
    view = self.getViewWidget()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\GraphicsItem.py", line 65, in getViewWidget
    if v is not None and not isQObjectAlive(v):

  File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\Qt.py", line 328, in isQObjectAlive
    return not sip.isdeleted(obj)
TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget

Tags: inpyselflibpackageslinesitenot