1

On my Rapberry Pi Model3 is installed by default python 3.9.2 I've correctly installed :

  • matplotlib 3.6.3
  • numpy 1.24.1

If I create a simple .py file like this:

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()  # Create a figure containing a single axes.

I receive this error:

Traceback (most recent call last):
  File "/home/pi/Desktop/test.py", line 31, in <module>
    fig = plt.figure(figsize=(5,3)) # start figure
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/_api/deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/pyplot.py", line 783, in figure
    manager = new_figure_manager(
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/pyplot.py", line 358, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/pyplot.py", line 336, in _warn_if_gui_out_of_main_thread
    if _get_required_interactive_framework(_get_backend_mod()):
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/pyplot.py", line 207, in _get_backend_mod
    switch_backend(dict.__getitem__(rcParams, "backend"))
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/pyplot.py", line 265, in switch_backend
    backend_mod = importlib.import_module(
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  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 "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/backends/backend_qt5agg.py", line 7, in <module>
    from .backend_qtagg import (    # noqa: F401, E402 # pylint: disable=W0611
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py", line 9, in <module>
    from .qt_compat import QT_API, _enum, _setDevicePixelRatio
  File "/home/pi/mytest/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py", line 137, in <module>
    raise ImportError(
ImportError: Failed to import any of the following Qt binding modules: PyQt6, PySide6, PyQt5, PySide2

Any idea? Thanks in advance.

2
  • How did you install matplotlib and numpy? Were they installed from the default repositories?
    – joan
    Jan 24, 2023 at 16:29
  • @joan, Yes, I've used default repositories
    – M4Biz
    Jan 24, 2023 at 16:37

1 Answer 1

3

Seems to be an error about missing Qt packages. Try and google the last line of the error (ImportError: Failed to import any of the following Qt binding modules: PyQt6, PySide6, PyQt5, PySide2).

Found something that can be helpful: https://stackoverflow.com/questions/52346254/importerror-failed-to-import-any-qt-binding-python-tensorflow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.