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

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

      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.

        1. matplot.py
          7 kB
          lang lang
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes