RuntimeError: could not open display

Hi all,
I'm new of osbpy.

I installed the osbypy packet under fedora 12 with python 2.6.
I had make a little script to plot dayly waveforms and when it run under command line, it seem running well, but when I run it under crontab the program get this error:

Traceback (most recent call last):
   File "/home/lenet/seiscomp3/bin/scwave", line 188, in <module>
     trackWave.plot(type='dayplot', outfile=FoderStoreImage+'/'+picture+Comp+'.jpg',size=(800, 600),starttime=UTCDateTime(TimeYesterday))
   File "/usr/lib/python2.6/site-packages/obspy-0.9.2-py2.6-linux-i686.egg/obspy/core/stream.py", line 1056, in plot
     from obspy.imaging.waveform import WaveformPlotting
   File "/usr/lib/python2.6/site-packages/obspy-0.9.2-py2.6-linux-i686.egg/obspy/imaging/waveform.py", line 18, in <module>
     import matplotlib.pyplot as plt
   File "/usr/lib/python2.6/site-packages/matplotlib/pyplot.py", line 95, in <module>
     new_figure_manager, draw_if_interactive, show = pylab_setup()
   File "/usr/lib/python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
     globals(),locals(),[backend_name])
   File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
     from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
   File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 8, in <module>
     import gtk; gdk = gtk.gdk
   File "/usr/lib/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
     _init()
   File "/usr/lib/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
     _gtk.init_check()
RuntimeError: could not open display

I have searched in internet, but I have not find anything.

Can anybody help me?

Thanks in advance

Sergio

Hi Sergio,

Looks like this is a matplotlib/sysadmin issue. The matplotlib library can use different “backends” which are the window system that actually plots the data. You are trying to use a TK-based backend (GTKAgg), which requires that you have a display specified. Your cron probably does not set this up before you call your python script? There are 2 things you could try:

  1. Use a different backend, that does not require a display. Some may be available, for others you may need to install additional packages. Change it in the first 2 lines of your main python script BEFORE importing obspy or anything else:

Hello Mark,

thanks for your answer.

I have made your suggested changes adding at the top of the script the two line

import matplotlib
matplotlib.use(‘Agg’)

but now it return me an other type of error:

ValueError: Format “jpg” is not supported.
Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz.
Exception TypeError: “‘NoneType’ object is not callable” in <bound method WaveformPlotting.del of <obspy.imaging.waveform.WaveformPlotting object at 0xaf77bcc>> ignored

For security I have call python in line command and then i did:

import matplotlib.pyplot as plt
fig = plt.figure()
Then i gave the command

print fig.canvas.get_supported_filetypes()
to know the supported output format and it reply with

{‘svgz’: ‘Scalable Vector Graphics’, ‘ps’: ‘Postscript’, ‘emf’: ‘Enhanced Metafile’, ‘svg’: ‘Scalable Vector Graphics’, ‘eps’: ‘Encapsulated Postscript’, ‘jpg’: ‘JPEG’, ‘raw’: ‘Raw RGBA bitmap’, ‘jpeg’: ‘JPEG’, ‘rgba’: ‘Raw RGBA bitmap’, ‘pdf’: ‘Portable Document Format’, ‘png’: ‘Portable Network Graphics’}

As you can see the jpg is supported

Sergio

Hi Sergio,

available output file formats could depend on the chosen backend. Also,
they depend on how your matplotlib was compiled. Are you sure that in
your cronjob the same Python interpreter is used? Crontabs usually lack
most of your environment variables in your normal login shell. You could
try to explicitely specify your Python interpreter.. e.g.

@daily /path/to/my/python myscript.py

Not sure what else could be the problem..

hope it helps,
Tobias