# RuntimeError: could not open display

**URL:** <https://discourse.obspy.org/t/runtimeerror-could-not-open-display/355>\
**Category:** Users Mailing List Archive\
**Tags:** archive\
**Created:** [October 3, 2014, 3:00pm UTC](https://discourse.obspy.org/t/runtimeerror-could-not-open-display/355 "2014-10-03T15:00:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergio59](https://discourse.obspy.org/user_avatar/discourse.obspy.org/sergio59/32/477_2.png) [@sergio59](https://discourse.obspy.org/u/sergio59)\
**Post date:** [October 3, 2014, 3:00pm UTC](https://discourse.obspy.org/t/runtimeerror-could-not-open-display/355/1 "2014-10-03T15:00:56Z")

</div>

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):  
&nbsp;&nbsp;&nbsp;File "/home/lenet/seiscomp3/bin/scwave", line 188, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackWave.plot(type='dayplot', outfile=FoderStoreImage+'/'+picture+Comp+'.jpg',size=(800, 600),starttime=UTCDateTime(TimeYesterday))  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/obspy-0.9.2-py2.6-linux-i686.egg/obspy/core/stream.py", line 1056, in plot  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from obspy.imaging.waveform import WaveformPlotting  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/obspy-0.9.2-py2.6-linux-i686.egg/obspy/imaging/waveform.py", line 18, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;import matplotlib.pyplot as plt  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/matplotlib/pyplot.py", line 95, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new\_figure\_manager, draw\_if\_interactive, show = pylab\_setup()  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/matplotlib/backends/\_\_init\_\_.py", line 25, in pylab\_setup  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;globals(),locals(),[backend\_name])  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend\_gtkagg.py", line 10, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from matplotlib.backends.backend\_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/matplotlib/backends/backend\_gtk.py", line 8, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;import gtk; gdk = gtk.gdk  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/gtk-2.0/gtk/\_\_init\_\_.py", line 64, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_init()  
&nbsp;&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/gtk-2.0/gtk/\_\_init\_\_.py", line 52, in \_init  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_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

---

<div class="post-metadata">

**Author:** ![Mark\_Williams](https://discourse.obspy.org/user_avatar/discourse.obspy.org/mark_williams/32/249_2.png) [@Mark\_Williams](https://discourse.obspy.org/u/Mark_Williams)\
**Post date:** [October 5, 2014, 4:07pm UTC](https://discourse.obspy.org/t/runtimeerror-could-not-open-display/355/2 "2014-10-05T16:07:11Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![sergio59](https://discourse.obspy.org/user_avatar/discourse.obspy.org/sergio59/32/477_2.png) [@sergio59](https://discourse.obspy.org/u/sergio59)\
**Post date:** [October 6, 2014, 8:32am UTC](https://discourse.obspy.org/t/runtimeerror-could-not-open-display/355/3 "2014-10-06T08:32:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)\
**Post date:** [October 8, 2014, 2:03pm UTC](https://discourse.obspy.org/t/runtimeerror-could-not-open-display/355/4 "2014-10-08T14:03:52Z")

</div>

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
