簡體   English   中英

在 PySide6 中使用 pyqtgraph 的遞歸錯誤

[英]Recursion Error using pyqtgraph with PySide6

我在使用 PySide6 實現 pyqtgraph 時遇到問題。 我已經將 pyqtgraph 與 PyQt5 一起使用,但我正在 PySide6 中專門為一個新項目制作一個新應用程序。

我檢查了 pyqtgraph 文檔,它說在 pyqtgraph 之前導入你的 Qt 包裝器,這樣它就知道要使用哪個。

import sys
from PySide6.QtWidgets import QMainWindow, QApplication, QTabWidget

from gui_scripts.tab_plot import PlotTab
import PySide6
import pyqtgraph as pg

from __feature__ import snake_case, true_property


class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.graph_widget = pg.PlotWidget()
        self.set_central_widget(self.graph_widget)
        hour = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        temperature = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
        self.graph_widget.plot(hour, temperature)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    main_window = MainWindow()
    main_window.show()

    sys.exit(app.exec())

我在 self.graph_widget = pg.PlotWidget() 處觸發了“RecursionError: maximum recursion depth exceeded while calling a Python object”

我使用這個示例https://www.pythonguis.com/tutorials/pyside-plotting-pyqtgraph/來生成相同的錯誤,因為我的實際實現是跨幾個腳本的。 該應用程序有一個導航選項卡,可以在幾個界面之間切換,其中一個是繪圖,在我為繪圖添加選項卡之前,代碼工作得很好。

編輯:當我不從 tab_plot 導入類時,代碼很好。 那個腳本是

from PySide6.QtWidgets import QWidget, QGridLayout
import sys
import pyqtgraph as pg

from __feature__ import snake_case, true_property


class PlotTab(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self)
        pg.setConfigOption('background', 'w')
        pg.setConfigOption('foreground', 'k')

        self.parent = parent

        self.layout = QGridLayout(self)
        self.plot1 = pg.PlotWidget()
        self.plot1.setLabel('left', 'Temperature (K)')
        self.plot1.setLabel('bottom', 'Voltage (V)')
        self.layout.add_widget(self.plot1, 0, 0)

Edit2:這是發生在以下位置的錯誤:self.plot1 = pg.PlotWidget() 文件“..\Python\Python310\lib\site-packages\pyqtgraph\widgets\PlotWidget.py”,第 51 行,在init GraphicsView 中。 init (self, parent, background=background)

文件“..\Python\Python310\lib\site-packages\pyqtgraph\widgets\GraphicsView.py”,第 73 行,在init self.useOpenGL(useOpenGL)

文件“..\Python\Python310\lib\site-packages\pyqtgraph\widgets\GraphicsView.py”,第168行,在useOpenGL self.setViewport(v)

文件“..\Python\Python310\lib\site-packages\pyqtgraph\widgets\PlotWidget.py”,第 78 行,在getattr if hasattr(self.plotItem, attr) 中:

File..\Python\Python310\lib\site-packages\pyqtgraph\widgets\PlotWidget.py", 第 78 行,在getattr if hasattr(self.plotItem, attr) 中:

文件“..\Python\Python310\lib\site-packages\pyqtgraph\widgets\PlotWidget.py”,第 78 行,在getattr if hasattr(self.plotItem, attr): [Previous line repeated 988 more times] RecursionError: maximum調用 Python 對象時超出遞歸深度

進程結束,退出代碼為 1

我認為你需要super(MainWindow, self).__init__()def __init__(self):

像這樣對我來說很好用

#!/usr/bin/env python3
from PySide6.QtWidgets import QApplication, QMainWindow
import pyqtgraph as pg
import sys


class MainWindow(QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()

        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)


app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec()

好吧,我想通了。 pyqtgraph 與 PySide6 中的 snake_case 功能不兼容。 我認為刪除它沒有影響,但它仍在導入正在使用它的腳本。

我遇到了同樣的問題並找到了答案:update your pyqtgraph's version

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM