Skip to content

Commit 9bed016

Browse files
Just check DISPLAY env var
1 parent 5a07c46 commit 9bed016

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/matplotlib/backends/backend_qt4.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@ def _create_qApp():
5656
app = QtGui.QApplication.instance()
5757
if app is None:
5858

59-
# try to launch a QApplication in a separate process
60-
# otherwise it may stop the intepreter on failure (if no X server for example)
61-
p = subprocess.Popen(sys.executable, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
62-
p.stdin.write('from matplotlib.backends.qt4_compat import QtGui\napp = QtGui.QApplication([])\n')
63-
p.stdin.close()
64-
if p.wait() != 0:
65-
raise RuntimeError( 'Qt4 failed to initialize ' + p.stderr.readline().rstrip() )
66-
59+
# check for DISPLAY env variable
60+
if sys.platform.startswith('linux'):
61+
display = os.environ.get('DISPLAY')
62+
if (display is None) or (not ':' in display.strip()):
63+
raise RuntimeError('Invalid DISPLAY variable')
64+
6765
qApp = QtGui.QApplication( [" "] )
6866
QtCore.QObject.connect( qApp, QtCore.SIGNAL( "lastWindowClosed()" ),
6967
qApp, QtCore.SLOT( "quit()" ) )

0 commit comments

Comments
 (0)