Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f5ae1f

Browse files
committed
MNT: check PySide, PyQt4, or PyQt5 are imported
If PySide, PyQt4, or PyQt5 are imported do not consult rcparams or ENV variable to decide which backend to use. This is a case where ignoring user input is sensible because the Qt bindings are mutually exclusive and attempting to import a second binding will fail. This can result in stand-alone scripts / mpl embeddings which are dependent on the rcparams to function correctly. Importing a specific Qt binding is stronger signal of user intent that either of the other two configuration options and should take precedence. closes #6164
1 parent c78ca18 commit 7f5ae1f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/matplotlib/backends/qt_compat.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,23 @@
4242

4343
QT_API = None
4444

45-
if (QT_API_ENV is not None):
45+
# check if any binding is already imported, if so silently ignore the
46+
# rcparams/ENV settings and use what ever is already imported.
47+
if 'PySide' in sys.modules:
48+
# user has imported PySide before importing mpl
49+
QT_API = QT_API_PYSIDE
50+
51+
if 'PyQt4' in sys.modules:
52+
# user has imported PyQt4 before importing mpl
53+
# this case also handles the PyQt4v2 case as once sip is imported
54+
# the API versions can not be changed so do not try
55+
QT_API = QT_API_PYQT
56+
57+
if 'PyQt5' in sys.modules:
58+
# the user has imported PyQt5 before importing mpl
59+
QT_API = QT_API_PYQT5
60+
61+
if (QT_API_ENV is not None) and QT_API is None:
4662
try:
4763
QT_ENV_MAJOR_VERSION = ETS[QT_API_ENV][1]
4864
except KeyError:

0 commit comments

Comments
 (0)