Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2276

Different import orders will affect the correctness of the combined code of pyside and matploblib

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.4.2
    • PySide
    • None
    • python 3.9, matploblib 3.7.1

    Description

      When used in combination with matploblib and pyside, the following import order will report an error

      from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
      from PySide6.QtWidgets import (QApplication, QComboBox, QHBoxLayout,
                                     QHeaderView, QLabel, QMainWindow, QSlider,
                                     QTableWidget, QTableWidgetItem, QVBoxLayout,
                                     QWidget)

      Error content:

      anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py", line 135, in <module>
          raise ImportError(
      ImportError: Failed to import any of the following Qt binding modules: PyQt6, PySide6, PyQt5, PySide2

       

      But as long as the upper and lower import order is reversed, the program will run correctly, that is, the following import order

      from PySide6.QtWidgets import (QApplication, QComboBox, QHBoxLayout,
                                     QHeaderView, QLabel, QMainWindow, QSlider,
                                     QTableWidget, QTableWidgetItem, QVBoxLayout,
                                     QWidget)
      from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 

       

      Theoretically, the order of imports should not affect whether the program can be executed correctly, and I haven't seen any document that needs to modify the order of imports, and I don't know why. The attached program verifies the problem I describe.

      Attachments

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            langx lang lang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: