Skip to content

[Bug]: import matplotlib.backends.backend_qt5agg error for pyside6 #24212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
koutoftimer opened this issue Oct 18, 2022 · 3 comments
Closed

[Bug]: import matplotlib.backends.backend_qt5agg error for pyside6 #24212

koutoftimer opened this issue Oct 18, 2022 · 3 comments

Comments

@koutoftimer
Copy link

Bug summary

_to_int = operator.attrgetter("value") if QT_API == "PyQt6" else int

Have to check for "PySide6" too.

Code for reproduction

$ QT_API=pyside6 python -c "import matplotlib.backends.backend_qt5agg"

Actual outcome

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/tmp.atoQSuHf68/venv/lib/python3.10/site-packages/matplotlib/backends/backend_qt5agg.py", line 7, in <module>
    from .backend_qtagg import (    # noqa: F401, E402 # pylint: disable=W0611
  File "/tmp/tmp.atoQSuHf68/venv/lib/python3.10/site-packages/matplotlib/backends/backend_qtagg.py", line 12, in <module>
    from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT
  File "/tmp/tmp.atoQSuHf68/venv/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py", line 72, in <module>
    _MODIFIER_KEYS = [
  File "/tmp/tmp.atoQSuHf68/venv/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py", line 73, in <listcomp>
    (_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

no errors

Additional information

PySide6==6.4.0

Operating system

GNU\Gentoo Linux

Matplotlib Version

3.6.1

Matplotlib Backend

same exception

Python version

3.10.6

Jupyter version

not installed

Installation

pip

@koutoftimer
Copy link
Author

I suppose it is already fixed in the main branch.

def _setup_pyqt5plus():
global QtCore, QtGui, QtWidgets, __version__
global _getSaveFileName, _isdeleted, _to_int
if QT_API == QT_API_PYQT6:
from PyQt6 import QtCore, QtGui, QtWidgets, sip
__version__ = QtCore.PYQT_VERSION_STR
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
QtCore.Property = QtCore.pyqtProperty
_isdeleted = sip.isdeleted
_to_int = operator.attrgetter('value')
elif QT_API == QT_API_PYSIDE6:
from PySide6 import QtCore, QtGui, QtWidgets, __version__
import shiboken6
def _isdeleted(obj): return not shiboken6.isValid(obj)
if parse_version(__version__) >= parse_version('6.4'):
_to_int = operator.attrgetter('value')
else:
_to_int = int
elif QT_API == QT_API_PYQT5:
from PyQt5 import QtCore, QtGui, QtWidgets
import sip
__version__ = QtCore.PYQT_VERSION_STR
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
QtCore.Property = QtCore.pyqtProperty
_isdeleted = sip.isdeleted
_to_int = int
elif QT_API == QT_API_PYSIDE2:
from PySide2 import QtCore, QtGui, QtWidgets, __version__
try:
from PySide2 import shiboken2
except ImportError:
import shiboken2
def _isdeleted(obj):
return not shiboken2.isValid(obj)
_to_int = int
else:
raise AssertionError(f"Unexpected QT_API: {QT_API}")
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
if QT_API in [QT_API_PYQT6, QT_API_PYQT5, QT_API_PYSIDE6, QT_API_PYSIDE2]:
_setup_pyqt5plus()

@koutoftimer
Copy link
Author

Yes it is fixed already. Can't reproduce the issue with main branch.

$ pip freeze
matplotlib @ git+https://github.com/matplotlib/matplotlib.git@80b15fb17be6455680a4830d0644731f8ee6bb8b
PySide6==6.4.0

For me works fine.

@oscargus
Copy link
Member

Was fixed in #24158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants