<h3 dir="auto">Bug summary</h3>
<p dir="auto">backend bug in matplotlib==3.6.1 with python3.11</p>
<p dir="auto">same issue happend when embeding  in Qt with PySide6==6.4.0.1</p>
<p dir="auto">error report<br>
int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'</p>
<p dir="auto">This is caused by the "The new Enum system" within the release of PySide6,  Qt for Python 6.4</p>
<p dir="auto">See<br>
<a href="https://www.qt.io/blog/qt-for-python-release-6.4-is-finally-here" rel="nofollow">Qt for python release 6.4 </a></p>
<p dir="auto">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.</p>
<p dir="auto">Quote below:</p>
<p dir="auto">The new Enum system</p>
<p dir="auto">One such area that we tackled now affects enums, which was implemented as bound C++ classes, but now it is updated to leverage <a href="https://docs.python.org/3/library/enum.html" rel="nofollow">Python's own enum mechanism</a>.</p>
<p dir="auto">Although the new Python enums and the old Shiboken-based ones are compatible with each other, but there are a few differences or restrictions:</p>
<p dir="auto">Python enums cannot be inherited from each other, whereas Shiboken enums can<br>
Python enums do not allow undefined values, Shiboken enums do<br>
Python enums always need exactly one argument, Shiboken enums have a default zero value<br>
Python enums rarely inherit from int, Shiboken enums always do<br>
You can see that  some of these differences are between flags. For example, until now, you could either write</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="flags = Qt.Alignment() 

enum = Qt.AlignmentFlag "><pre class="notranslate"><code class="notranslate">flags = Qt.Alignment() 

enum = Qt.AlignmentFlag 
</code></pre></div>
<p dir="auto">or use the enum shortcuts like these:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Qt.AlignLeft = Qt.AlignmentFlag.AlignLeft 

Qt.AlignTop  = Qt.AlignmentFlag.AlignTop"><pre class="notranslate"><code class="notranslate">Qt.AlignLeft = Qt.AlignmentFlag.AlignLeft 

Qt.AlignTop  = Qt.AlignmentFlag.AlignTop
</code></pre></div>
<p dir="auto">These shortcuts, and flags no longer exist (officially) from 6.4.0 onwards. Instead, Python has an <a href="https://docs.python.org/3/library/enum.html#enum.Flag" rel="nofollow">enum.Flags</a> class, which is a subclass of the <a href="https://docs.python.org/3/library/enum.html#enum.Enum" rel="nofollow">enum.Enum</a> class.</p>
<p dir="auto">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</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="flags = Qt.Alignment() 

enum = Qt.AlignLeft 

item.setForeground(QColor(Qt.green)) 

flags_type = QPainter.RenderHints 

flags = QPainter.RenderHints() 

chart_view.setRenderHint(QPainter.Antialiasing) "><pre class="notranslate"><code class="notranslate">flags = Qt.Alignment() 

enum = Qt.AlignLeft 

item.setForeground(QColor(Qt.green)) 

flags_type = QPainter.RenderHints 

flags = QPainter.RenderHints() 

chart_view.setRenderHint(QPainter.Antialiasing) 
</code></pre></div>
<p dir="auto">you get a construct that mimics the following code, which is the recommended way of using flags and enums:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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) "><pre class="notranslate"><code class="notranslate">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) 
</code></pre></div>
<p dir="auto">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.</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib
print(matplotlib.get_backend())

or 

from matplotlib.backends.qt_compat import QtWidgets
from matplotlib.backends.backend_qtagg import (
    FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
from matplotlib.figure import Figure"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-en">print</span>(<span class="pl-s1">matplotlib</span>.<span class="pl-en">get_backend</span>())

<span class="pl-s1">or</span> 

<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">backends</span>.<span class="pl-s1">qt_compat</span> <span class="pl-k">import</span> <span class="pl-v">QtWidgets</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">backends</span>.<span class="pl-s1">backend_qtagg</span> <span class="pl-k">import</span> (
    <span class="pl-v">FigureCanvas</span>, <span class="pl-v">NavigationToolbar2QT</span> <span class="pl-k">as</span> <span class="pl-v">NavigationToolbar</span>)
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">figure</span> <span class="pl-k">import</span> <span class="pl-v">Figure</span></pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">Traceback (most recent call last):<br>
File "", line 1, in <br>
File "C:\Python311\Lib\site-packages\matplotlib_<em>init</em>_.py", line 1182, in get_backend<br>
return rcParams['backend']<br>
~~~~~~~~^^^^^^^^^^^<br>
File "C:\Python311\Lib\site-packages\matplotlib_<em>init</em>_.py", line 677, in <strong>getitem</strong><br>
plt.switch_backend(rcsetup.<em>auto_backend_sentinel)<br>
File "C:\Python311\Lib\site-packages\matplotlib\pyplot.py", line 252, in switch_backend<br>
switch_backend(candidate)<br>
File "C:\Python311\Lib\site-packages\matplotlib\pyplot.py", line 265, in switch_backend<br>
backend_mod = importlib.import_module(<br>
^^^^^^^^^^^^^^^^^^^^^^^^<br>
File "C:\Python311\Lib\importlib_<em>init</em></em>.py", line 126, in import_module<br>
return _bootstrap._gcd_import(name[level:], package, level)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
File "", line 1206, in _gcd_import<br>
File "", line 1178, in _find_and_load<br>
File "", line 1149, in _find_and_load_unlocked<br>
File "", line 690, in _load_unlocked<br>
File "", line 940, in exec_module<br>
File "", line 241, in _call_with_frames_removed<br>
File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qtagg.py", line 12, in <br>
from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT<br>
File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qt.py", line 72, in <br>
_MODIFIER_KEYS = [<br>
^<br>
File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qt.py", line 73, in <br>
(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">QtAgg</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Windows</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.6.1</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">error as reported</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.11</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto">pip</p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">Error while importing matplotlib qt backend.</p>
<p dir="auto">The version details are as below<br>
matplotlib: 3.6.1<br>
pyside: 6.4.0<br>
python: 3.9.9</p>
<p dir="auto">on a macOS-M1 machine.</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">backends</span>.<span class="pl-s1">backend_qtagg</span> <span class="pl-k">import</span> <span class="pl-v">NavigationToolbar2QT</span> <span class="pl-k">as</span> <span class="pl-v">NavigationToolbar</span></pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">Traceback (most recent call last):<br>
File "", line 1, in <br>
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py", line 12, in <br>
from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT<br>
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qt.py", line 72, in <br>
_MODIFIER_KEYS = [<br>
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qt.py", line 73, in <br>
(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),<br>
TypeError: int() argument must be a string, a bytes-like object or a number, not 'KeyboardModifier'</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">No error!</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">OS/X</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.6.1</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">MacOSX</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.9.9</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto">pip</p>