Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
pyplot cannot be imported. Raises an error pertaining to converting Qt Enumerations to integers.
Code for reproduction
importmatplotlib.pyplotasplt"""Error is thrown on import"""# addendumimportmatplotlib# This also produces the same error (same source)matplotlib.get_backend()
Actual outcome
Traceback (most recent call last):
File ".../test.py", line 2, in
import matplotlib.pyplot as plt
File "/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2230, in/.local/lib/python3.10/site-packages/matplotlib/init.py", line 672, ingetitem
switch_backend(rcParams["backend"])
File "
plt.switch_backend(rcsetup._auto_backend_sentinel)
File "/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 247, in switch_backend/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 267, in switch_backend
switch_backend(candidate)
File "
class backend_mod(matplotlib.backend_bases._Backend):
File "/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 268, in backend_mod/.local/lib/python3.10/site-packages/matplotlib/backends/backend_qtagg.py", line 12, in
locals().update(vars(importlib.import_module(backend_name)))
File "/usr/lib64/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "
from .backend_qt import (
File "/.local/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py", line 73, in/.local/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py", line 74, in
_MODIFIER_KEYS = [
File "
(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'
Expected outcome
Nothing, execute and exit
Additional information
The source of the error is the enumerations used in PySide6 (for me). Inmatplotlib/qt_compat.py
, the
enumerations returned from _enum cannot be directly converted to integers with _to_int; the issue can be resolved by extending the QT_API condition in _to_int()[qt_compat.py+143] to include "pyside6".
Alternatively, I can set QT_API in the environment from the various expected values at the top of qt_compat.py (pyside6, pyqt5, pyside2, etc.); pyside6 is the only compatibility mode which raises this particular error.
Operating system
Fedora
Matplotlib Version
3.5.1
Matplotlib Backend
PySide6 (matplotlib.get_backend() also raises the same error described)
Python version
3.10.11
Jupyter version
n-a
Installation
pip