Skip to content

Commit 5ce866c

Browse files
committed
Try importing PySide, if we can't find sip.
If no QT_API is specified, we use the value in rcParams and the default value for this is PyQt. If a user has PySide installed, trying to use the qt backend fails, unless QT_API is specified or the config file is modified. This commit, adds code to try and import PySide, if an import of PyQt fails.
1 parent 43bf56e commit 5ce866c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/matplotlib/backends/qt4_compat.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,19 @@
3131
# of file dialog.
3232
_getSaveFileName = None
3333

34+
# Flag to check if sip could be imported
35+
_sip_imported = False
36+
3437
# Now perform the imports.
3538
if QT_API in (QT_API_PYQT, QT_API_PYQTv2):
36-
import sip
39+
try:
40+
import sip
41+
_sip_imported = True
42+
except ImportError:
43+
# Try using PySide
44+
QT_API = QT_API_PYSIDE
45+
46+
if _sip_imported:
3747
if QT_API == QT_API_PYQTv2:
3848
if QT_API_ENV == 'pyqt':
3949
cond = ("Found 'QT_API=pyqt' environment variable. "
@@ -76,7 +86,7 @@
7686
# call to getapi() can fail in older versions of sip
7787
_getSaveFileName = QtGui.QFileDialog.getSaveFileName
7888

79-
else: # can only be pyside
89+
else: # try importing pyside
8090
from PySide import QtCore, QtGui, __version__, __version_info__
8191
if __version_info__ < (1, 0, 3):
8292
raise ImportError(

0 commit comments

Comments
 (0)