question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some extension modules do not have proper __package__ in standalone mode, causing errors in new Matplotlib

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, Nov 30, 2021

This is now on develop and will be part of 0.6.18 which will be release soon.

1reaction
kayhayencommented, Nov 30, 2021

Should be good on factory: https://nuitka.net/doc/factory.html

Strangness is Python eco system normality, default, you name it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1. Extending Python with C or C++ — Python 3.11.1 ...
Such extension modules can do two things that can't be done directly in Python: they can implement new built-in object types, and they...
Read more >
Troubleshooting — Matplotlib 3.6.2 documentation
If you would like to use a different configuration directory, you can do so by specifying the location in your MPLCONFIGDIR environment variable...
Read more >
Python Plotting With Matplotlib (Guide)
If you don't already have matplotlib installed, see here for a walkthrough before proceeding. ... But the following issues can cause some challenges:....
Read more >
Installation Issues — mod_wsgi 4.9.4 documentation
To remedy the problem, install the developer package for Python corresponding to the Python runtime package you have installed. What the name of...
Read more >
Visualization with Matplotlib | Python Data Science Handbook
Matplotlib is a multi-platform data visualization library built on NumPy arrays, ... and people have been developing new packages that build on its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found