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

Skip to content

Commit b7de089

Browse files
committed
Backport PR ipython#2757: check for complete pyside presence before trying to import
importing pyside partially and then falling back to pyqt causes a crash in sip (see ipythongh-1431) To avoid it try to locate all modules before the import and should that fail print a warning. debian splits pyside into many small packages so sometimes people end up with incomplete pyside installations.
1 parent 9eb1365 commit b7de089

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

IPython/external/qt.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,32 @@ def prepare_pyqt4():
2323
# Select Qt binding, using the QT_API environment variable if available.
2424
QT_API = os.environ.get('QT_API')
2525
if QT_API is None:
26+
pyside_found = False
2627
try:
2728
import PySide
2829
if PySide.__version__ < '1.0.3':
2930
# old PySide, fallback on PyQt
3031
raise ImportError
32+
# we can't import an incomplete pyside and pyqt4
33+
# this will cause a crash in sip (#1431)
34+
# check for complete presence before importing
35+
import imp
36+
imp.find_module("QtCore", PySide.__path__)
37+
imp.find_module("QtGui", PySide.__path__)
38+
imp.find_module("QtSvg", PySide.__path__)
39+
pyside_found = True
3140
from PySide import QtCore, QtGui, QtSvg
3241
QT_API = QT_API_PYSIDE
3342
except ImportError:
3443
try:
3544
prepare_pyqt4()
3645
import PyQt4
3746
from PyQt4 import QtCore, QtGui, QtSvg
47+
if pyside_found:
48+
print "WARNING: PySide installation incomplete and PyQt4 " \
49+
"present.\nThis will likely crash, please install " \
50+
"PySide completely, remove PySide or PyQt4 or set " \
51+
"the QT_API environment variable to pyqt or pyside"
3852
if QtCore.PYQT_VERSION_STR < '4.7':
3953
# PyQt 4.6 has issues with null strings returning as None
4054
raise ImportError

0 commit comments

Comments
 (0)