I have a slight modified version of this example from matplotlib: https://matplotlib.org/gallery/user_interfaces/embedding_in_qt_sgskip.html
The only thing changed is the imports since I am using PySide2, so the imports looks like this:
from PySide2 import QtCore, QtWidgets
from matplotlib.backends.backend_qt5agg import (FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
from matplotlib.figure import Figure
This works fine when running the code in pycharm, or running the scrips by itself, however after an .exe is created with PyInstaller I get the following error:
TypeError: 'PySide2.QtWidgets.QBoxLayout.addWidget' called with wrong argument types:
PySide2.QtWidgets.QBoxLayout.addWidget(FigureCanvasQTAgg)
Supported signatures:
PySide2.QtWidgets.QBoxLayout.addWidget(PySide2.QtWidgets.QWidget, int=0,
PySide2.QtCore.Qt.Alignment=Default(Qt.Alignment))
PySide2.QtWidgets.QBoxLayout.addWidget(PySide2.QtWidgets.QWidget)
It seems as the FigureCanvasQtAgg is no longer recognized as a QWidget, so it can't be added to the layout.
I've tried adding these lines to suggest pyside as suggested here:
os.environ["QT_API"] = "PySide2"
matplotlib.use('Qt5Agg')
matplotlib.rcParams['backend.qt5']='PySide2'
However that does not change the error message of the exe. In pycharm it still runs fine.
EDIT: It seems this is some problem with PySide2+PyInstaller, after replacing this line:
from PySide2 import QtCore, QtWidgets
with this line:
from PyQt5 import QtCore, QtWidgets
It works even after using PyInstaller.
But I want to use PySide2 instead of PyQt5, anyone know a way to solve this?