Some extension modules do not have proper __package__ in standalone mode, causing errors in new Matplotlib
See original GitHub issueHi there, This issue happens with PySide6 and MatPlotLib 3.5.0.rc1 - the version of matplotlib that supports PySide6 & PyQt6. I know it’s not the current stable version, but should be released soon and at the very least you’ll have a heads up for when it is. I can compile without error, but when running the compiled binary, it gives this error:
Traceback (most recent call last):
File "/home/theguy/projects/test_nuitka/plot.dist/plot.py", line 5, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "/home/theguy/projects/test_nuitka/plot.dist/matplotlib/backends/backend_qtagg.py", line 12, in <module matplotlib.backends.backend_qtagg>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "/home/theguy/projects/test_nuitka/plot.dist/matplotlib/backends/backend_qt.py", line 28, in <module matplotlib.backends.backend_qt>
File "/home/theguy/projects/test_nuitka/plot.dist/matplotlib/backends/backend_qt.py", line 29, in <dictcontraction>
File "/home/theguy/projects/test_nuitka/plot.dist/matplotlib/backends/qt_compat.py", line 153, in _enum
KeyError: None
I see that MatPlotLib has changed how their QT backend setup works a bit with the support for PySide6: https://github.com/matplotlib/matplotlib/pull/19255
The KeyError reported comes from this line:
sys.modules[QtCore.__package__]
My setup: 0.6.18rc6 (Also tested against 0.6.17.5) Commercial: None Python: 3.9.5 (default, May 11 2021, 08:20:37) Executable: /home/theguy/.cache/pypoetry/virtualenvs/test-nuitka-Z7Y54p4h-py3.9/bin/python OS: Linux Arch: x86_64
VirtualEnv managed with: Poetry
Specific versions used: matplotlib-3.5.0rc1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl numpy-1.21.3-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl PySide6-6.2.1-6.2.1-cp36.cp37.cp38.cp39.cp310-abi3-manylinux1_x86_64.whl shiboken6-6.2.1-6.2.1-cp36.cp37.cp38.cp39.cp310-abi3-manylinux1_x86_64.whl
Hello World example for reproduction:
plot.py
import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (QApplication, QLabel, QVBoxLayout, QWidget)
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from matplotlib.figure import Figure
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
super(MplCanvas, self).__init__(fig)
class MyWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
self.text = QLabel("Hello World")
self.text.setAlignment(Qt.AlignCenter)
sc = MplCanvas(self, width=5, height=4, dpi=100)
sc.axes.plot([0, 1, 2, 3, 4], [10, 1, 20, 3, 40])
self.layout = QVBoxLayout()
self.layout.addWidget(self.text)
self.layout.addWidget(sc)
self.setLayout(self.layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = MyWidget()
widget.resize(800, 600)
widget.show()
sys.exit(app.exec())
Nuitka options:
python -m nuitka --follow-imports --standalone --plugin-enable=numpy --plugin-enable=pyside6 plot.py
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (9 by maintainers)
Top GitHub Comments
This is now on develop and will be part of 0.6.18 which will be release soon.
Should be good on factory: https://nuitka.net/doc/factory.html
Strangness is Python eco system normality, default, you name it.