Skip to content

workaround for matplotlib on X-less remote logins

David Keitel requested to merge (removed):nox into master

Hi Greg, logged into a remote (e.g. LDG cluster) without X-forwarding, importing pyfstat fails for me:

import pyfstat
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyfstat/", line 3, in <module>
    from .core import BaseSearchClass, ComputeFstat, Writer, SemiCoherentSearch, SemiCoherentGlitchSearch
  File "pyfstat/", line 9, in <module>
    import matplotlib.pyplot as plt
  File "/usr/lib64/python2.7/site-packages/matplotlib/", line 97, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/", line 25, in pylab_setup
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/", line 10, in <module>
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/", line 13, in <module>
    import gtk; gdk = gtk.gdk
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/", line 64, in <module>
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/", line 52, in _init
RuntimeError: could not open display

I cobbled together the following workaround, let me know if you have a better solution:

-first check $DISPLAY environment variable
-then use non-interactive "AGG" backend if necessary

Merge request reports