-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Working with PyQt5, the different import order will make different result. #21998
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
Comments
Both ways work fine for me; are you certain that Matplotlib loaded PyQt5 and not PySide2? See this explanation, but the safest way to guarantee that Matplotlib loads the intended Qt wrapper is to import it first. |
Thanks, I got it. I tried it in a new python environment which just install matplotlib and pyqt5, the program will run correctlly. So I checked the python pip environment which cause the TypeError, it contains both pyqt5 and pyside6. At that time the matplotlib automatically import pyside6, which will conflict with the later imported pyqt5 and generate an error. Thanks again! |
Ah yes, this would have broken in 3.5, because it added support for both Python wrappers of Qt6. |
I am going to re-open this, even though you can work around this by changing the import order, we should not have that sort of brittleness. I'm working on a PR to fix this. |
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). closes matplotlib#21998
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). closes matplotlib#21998
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). closes matplotlib#21998
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). closes matplotlib#21998 Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). Additional changes to qt_compat that only matters if 1. rcparams['backend'] is set to qt5agg or qt5agg 2. QT_API env is not set 3. the user directly import matplotlib.backends.qt_compat This will likely only affect users who are using Matplotlib as an qt-shim implementation. closes matplotlib#21998 Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). Additional changes to qt_compat that only matters if 1. rcparams['backend'] is set to qt5agg or qt5agg 2. QT_API env is not set 3. the user directly import matplotlib.backends.qt_compat This will likely only affect users who are using Matplotlib as an qt-shim implementation. closes matplotlib#21998 Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). Additional changes to qt_compat that only matters if 1. rcparams['backend'] is set to qt5agg or qt5agg 2. QT_API env is not set 3. the user directly import matplotlib.backends.qt_compat This will likely only affect users who are using Matplotlib as an qt-shim implementation. closes matplotlib#21998 Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). Additional changes to qt_compat that only matters if 1. rcparams['backend'] is set to qt5agg or qt5agg 2. QT_API env is not set 3. the user directly import matplotlib.backends.qt_compat This will likely only affect users who are using Matplotlib as an qt-shim implementation. closes matplotlib#21998 Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Because the code in qt_compat tries qt6 bindings first, backend_qt supports both Qt5 and Qt6, and the qt5 named backends are shims to the generic Qt backend, if you imported matplotlib.backends.backend_qt5agg, matplotlib.backends.backend_qt5cairo, or matplotlib.backends.backend_qt5, and 1. had PyQt6 or pyside6 installed 2. had not previously imported a Qt5 binding Then you will end up with a backend that (by name) claims to be Qt5, but will be using Qt6 bindings. If you then subsequently import a Qt6 binding and try to embed the canvas it will fail (due to being Qt6 objects not Qt5 objects!). Additional changes to qt_compat that only matters if 1. rcparams['backend'] is set to qt5agg or qt5agg 2. QT_API env is not set 3. the user directly import matplotlib.backends.qt_compat This will likely only affect users who are using Matplotlib as an qt-shim implementation. closes matplotlib#21998 Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
This works around matplotlib/matplotlib#21998 by importing PyQt5 before matplotlib. The bug was introduced in matplotlib 3.5 and fixed in 3.5.2, but Ubuntu 22.04 ships with 3.5.1. Signed-off-by: Clayton Smith <argilo@gmail.com>
This works around matplotlib/matplotlib#21998 by importing PyQt5 before matplotlib. The bug was introduced in matplotlib 3.5 and fixed in 3.5.2, but Ubuntu 22.04 ships with 3.5.1. Signed-off-by: Clayton Smith <argilo@gmail.com>
This works around matplotlib/matplotlib#21998 by importing PyQt5 before matplotlib. The bug was introduced in matplotlib 3.5 and fixed in 3.5.2, but Ubuntu 22.04 ships with 3.5.1. Signed-off-by: Clayton Smith <argilo@gmail.com> (cherry picked from commit 76bd672) Signed-off-by: Jeff Long <willcode4@gmail.com>
This works around matplotlib/matplotlib#21998 by importing PyQt5 before matplotlib. The bug was introduced in matplotlib 3.5 and fixed in 3.5.2, but Ubuntu 22.04 ships with 3.5.1. Signed-off-by: Clayton Smith <argilo@gmail.com> (cherry picked from commit 76bd672) Signed-off-by: Jeff Long <willcode4@gmail.com>
This works around matplotlib/matplotlib#21998 by importing PyQt5 before matplotlib. The bug was introduced in matplotlib 3.5 and fixed in 3.5.2, but Ubuntu 22.04 ships with 3.5.1. Signed-off-by: Clayton Smith <argilo@gmail.com> (cherry picked from commit 76bd672) Signed-off-by: Jeff Long <willcode4@gmail.com>
This works around matplotlib/matplotlib#21998 by importing PyQt5 before matplotlib. The bug was introduced in matplotlib 3.5 and fixed in 3.5.2, but Ubuntu 22.04 ships with 3.5.1. Signed-off-by: Clayton Smith <argilo@gmail.com> (cherry picked from commit 76bd672) Signed-off-by: Jeff Long <willcode4@gmail.com>
Obrigado! |
This works around matplotlib/matplotlib#21998 by importing PyQt5 before matplotlib. The bug was introduced in matplotlib 3.5 and fixed in 3.5.2, but Ubuntu 22.04 ships with 3.5.1. Signed-off-by: Clayton Smith <argilo@gmail.com>
Bug summary
Working with PyQt5, the different import order will make different result.
TypeError
at the method ofQLayout.addWidget
.Code for reproduction
Actual outcome
Expected outcome
expect no TypeError
Additional information
This Bug will not happen at the version v3.4.x of matplotlib.
Operating system
Windows
Matplotlib Version
3.5.1
Matplotlib Backend
QtAgg
Python version
Python 3.8.10
Installation
pip
The text was updated successfully, but these errors were encountered: