gtk backend failure on systems without gtk

On some OSX systems, pylab is failing on importing pylab because of lack of GTK. This appears to be a bug; if the system doesnt have gtk, it should simply not import that backend to begin with.

>>> from matplotlib import pylab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5-macosx-10.5-i386.egg/matplotlib/pylab.py", line 292, in <module>
   from matplotlib.pyplot import *
File "/Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5-macosx-10.5-i386.egg/matplotlib/pyplot.py", line 39, in <module>
   new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5-macosx-10.5-i386.egg/matplotlib/backends/__init__.py", line 24, in pylab_setup
   globals(),locals(),[backend_name])
File "/Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5-macosx-10.5-i386.egg/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
   from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "/Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5-macosx-10.5-i386.egg/matplotlib/backends/backend_gtk.py", line 6, in <module>
   import gobject
ImportError: No module named gobject

···

matplotlib does not do runtime checking to see if a backend is
available (arguably it should, but it does not_. It does do compile
time checking, and if gtk was available at compile time it will spit
out a default matplotlib rc file which uses gtkagg. If you ship this
to your users who do not have gtk, it can cause problems (you can
tweak this with setup.cfg).

You may want to make tkagg the default backend if you are distributing
binaries, since it is most likely to work on the user side.

JDH

···

On Jan 13, 2008 7:26 PM, Christopher Fonnesbeck <fonnesbeck@...935...> wrote:

On some OSX systems, pylab is failing on importing pylab because of
lack of GTK. This appears to be a bug; if the system doesnt have gtk,
it should simply not import that backend to begin with.