Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: backend bug in matplotlib==3.6.1 with python3.11 and PySide6==6.4.0.1 #24332

Closed
@zlmturnout

Description

@zlmturnout

Bug summary

backend bug in matplotlib==3.6.1 with python3.11

same issue happend when embeding in Qt with PySide6==6.4.0.1

error report
int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'

This is caused by the "The new Enum system" within the release of PySide6, Qt for Python 6.4

See
Qt for python release 6.4

PySide is in the interesting position of being both Qt (with its C++ roots and all that entails) but also distinctly Python. Where possible, we strive to align PySide further with Python conventions and use as many Python features as we can, if they make sense.

Quote below:

The new Enum system

One such area that we tackled now affects enums, which was implemented as bound C++ classes, but now it is updated to leveragePython's own enum mechanism.

Although the new Python enums and the old Shiboken-based ones are compatible with each other, but there are a few differences or restrictions:

Python enums cannot be inherited from each other, whereas Shiboken enums can
Python enums do not allow undefined values, Shiboken enums do
Python enums always need exactly one argument, Shiboken enums have a default zero value
Python enums rarely inherit from int, Shiboken enums always do
You can see that some of these differences are between flags. For example, until now, you could either write

flags = Qt.Alignment() enum = Qt.AlignmentFlag

or use the enum shortcuts like these:

Qt.AlignLeft = Qt.AlignmentFlag.AlignLeft Qt.AlignTop  = Qt.AlignmentFlag.AlignTop

These shortcuts, and flags no longer exist (officially) from 6.4.0 onwards. Instead, Python has anenum.Flags class, which is a subclass of theenum.Enum class.

If the thought of updating all your code left and right makes you sweat more than an overheated pumpkin spice latte, do not fret, for salvation has a name, and it’s “forgiveness mode”. This transitory mode allows you to continue using the old constructs but translates them internally into the new ones. For example, if you write

flags = Qt.Alignment() enum = Qt.AlignLeft item.setForeground(QColor(Qt.green)) flags_type = QPainter.RenderHints flags = QPainter.RenderHints() chart_view.setRenderHint(QPainter.Antialiasing)

you get a construct that mimics the following code, which is the recommended way of using flags and enums:

flags = Qt.AlignmentFlag(0) enum = Qt.AlignmentFlag.AlignLeft item.setForeground(QColor(Qt.GlobalColor.green)) flags_type = QPainter.RenderHint flags = QPainter.RenderHint(0) chart_view.setRenderHint(QPainter.RenderHint.Antialiasing)

With this you can at least initially ignore the difference between old and new enums, as long as the new enums are properties of classes.

Code for reproduction

importmatplotlibprint(matplotlib.get_backend())orfrommatplotlib.backends.qt_compatimportQtWidgetsfrommatplotlib.backends.backend_qtaggimport (FigureCanvas,NavigationToolbar2QTasNavigationToolbar)frommatplotlib.figureimportFigure

Actual outcome

Traceback (most recent call last):
File "", line 1, in
File "C:\Python311\Lib\site-packages\matplotlib_init_.py", line 1182, in get_backend
return rcParams['backend']
~~~~~~~~^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\matplotlib_init_.py", line 677, ingetitem
plt.switch_backend(rcsetup.auto_backend_sentinel)
File "C:\Python311\Lib\site-packages\matplotlib\pyplot.py", line 252, in switch_backend
switch_backend(candidate)
File "C:\Python311\Lib\site-packages\matplotlib\pyplot.py", line 265, in switch_backend
backend_mod = importlib.import_module(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qtagg.py", line 12, in
from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT
File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qt.py", line 72, in
_MODIFIER_KEYS = [
^
File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qt.py", line 73, in
(_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

QtAgg

Additional information

No response

Operating system

Windows

Matplotlib Version

3.6.1

Matplotlib Backend

error as reported

Python version

3.11

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp