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/__init__.py", line 3, in <module>
    from .core import BaseSearchClass, ComputeFstat, Writer, SemiCoherentSearch, SemiCoherentGlitchSearch
  File "pyfstat/core.py", line 9, in <module>
    import matplotlib.pyplot as plt
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 97, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
    globals(),locals(),[backend_name])
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 13, in <module>
    import gtk; gdk = gtk.gdk
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
    _init()
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
    _gtk.init_check()
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

Loading