non-interactive matplotlib use with no X-server

I am trying to use matplotlib to generate some figures non-interactively
via cron, but I can not seem to get matplotlib.figure to import without
a gtk error, even when I specify to use an image backend. The problem
seems to be related to trying to import gtk when no X server is present.
The script runs fine when i am logged in locally, and when logged in
remotetely with X11 forwarding, but it fails when run through cron or
when logged in remotely with no X-server. It also does not help if I run
the script as: python script -dAgg

I am running matplotlib 0.91.1. Any hints on how to make this work? Am I
missing something here?

Thanks!

j

Here is an example (minimal) script that causes the error:

#start script
import matplotlib
matplotlib.use('Agg')

import matplotlib.figure
#end script

Output=
Traceback (most recent call last):
  File "nox_test.py", line 5, in ?
    import matplotlib.figure
  File
"/home/jkitchin/lib/python2.4/site-packages/matplotlib/figure.py", line
10, in ?
    from axes import Axes, Subplot, PolarSubplot, PolarAxes
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/axes.py",
line 13, in ?
    from matplotlib import axis as maxis
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/axis.py",
line 14, in ?
    from patches import bbox_artist
  File
"/home/jkitchin/lib/python2.4/site-packages/matplotlib/patches.py", line
12, in ?
    import matplotlib.mlab as mlab
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/mlab.py",
line 2481, in ?
    class SortedStringsScrolledWindow(gtk.ScrolledWindow):
NameError: name 'gtk' is not defined

···

--
-----------------------------------
John Kitchin
Assistant Professor
Doherty Hall 4210A
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

John Kitchin wrote:

I am trying to use matplotlib to generate some figures non-interactively
via cron, but I can not seem to get matplotlib.figure to import without
a gtk error, even when I specify to use an image backend. The problem
seems to be related to trying to import gtk when no X server is present.
The script runs fine when i am logged in locally, and when logged in
remotetely with X11 forwarding, but it fails when run through cron or
when logged in remotely with no X-server. It also does not help if I run
the script as: python script -dAgg

I am running matplotlib 0.91.1. Any hints on how to make this work? Am I
missing something here?

John,

No, you have tripped over a bug that was fixed in the latest release, announced earlier this week. The problem was that for a brief period, including the 0.91.1 release, mlab.py included some gtk gui code. Now this has been moved out of the way to another module, so gtk won't be imported by accident.

If you can replace your mpl with 0.91.2, that will solve your problem.

Eric

···

Thanks!

j

Here is an example (minimal) script that causes the error:

#start script
import matplotlib
matplotlib.use('Agg')

import matplotlib.figure
#end script

Output=
Traceback (most recent call last):
  File "nox_test.py", line 5, in ?
    import matplotlib.figure
  File
"/home/jkitchin/lib/python2.4/site-packages/matplotlib/figure.py", line
10, in ?
    from axes import Axes, Subplot, PolarSubplot, PolarAxes
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/axes.py",
line 13, in ?
    from matplotlib import axis as maxis
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/axis.py",
line 14, in ?
    from patches import bbox_artist
  File
"/home/jkitchin/lib/python2.4/site-packages/matplotlib/patches.py", line
12, in ?
    import matplotlib.mlab as mlab
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/mlab.py",
line 2481, in ?
    class SortedStringsScrolledWindow(gtk.ScrolledWindow):
NameError: name 'gtk' is not defined

Thanks! Upgrading to 0.91.2 fixed the problem.

j

Eric Firing wrote:

···

John Kitchin wrote:

I am trying to use matplotlib to generate some figures non-interactively
via cron, but I can not seem to get matplotlib.figure to import without
a gtk error, even when I specify to use an image backend. The problem
seems to be related to trying to import gtk when no X server is present.
The script runs fine when i am logged in locally, and when logged in
remotetely with X11 forwarding, but it fails when run through cron or
when logged in remotely with no X-server. It also does not help if I run
the script as: python script -dAgg

I am running matplotlib 0.91.1. Any hints on how to make this work? Am I
missing something here?

John,

No, you have tripped over a bug that was fixed in the latest release,
announced earlier this week. The problem was that for a brief period,
including the 0.91.1 release, mlab.py included some gtk gui code. Now
this has been moved out of the way to another module, so gtk won't be
imported by accident.

If you can replace your mpl with 0.91.2, that will solve your problem.

Eric

Thanks!

j

Here is an example (minimal) script that causes the error:

#start script
import matplotlib
matplotlib.use('Agg')

import matplotlib.figure
#end script

Output=
Traceback (most recent call last):
  File "nox_test.py", line 5, in ?
    import matplotlib.figure
  File
"/home/jkitchin/lib/python2.4/site-packages/matplotlib/figure.py", line
10, in ?
    from axes import Axes, Subplot, PolarSubplot, PolarAxes
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/axes.py",
line 13, in ?
    from matplotlib import axis as maxis
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/axis.py",
line 14, in ?
    from patches import bbox_artist
  File
"/home/jkitchin/lib/python2.4/site-packages/matplotlib/patches.py", line
12, in ?
    import matplotlib.mlab as mlab
  File "/home/jkitchin/lib/python2.4/site-packages/matplotlib/mlab.py",
line 2481, in ?
    class SortedStringsScrolledWindow(gtk.ScrolledWindow):
NameError: name 'gtk' is not defined

--
-----------------------------------
John Kitchin
Assistant Professor
Doherty Hall 4210A
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu