I notice that pygtk.require(‘2.0’) calls have appeared
in backend_gtk.py and backend_gdk.py
I am not convinced that library code should include calls to
The problem is that pygtk.require() has to be called >before<
This means that if you are using gtk then you have two choices:
- never use pygtk.require()
- always precede any ‘import gtk’ with ‘import
pygtk’ and ‘pygtk.require(‘2.0’)’
I have found that 1. works pretty well and prefer not to litter
code with the pygtk.require() boiler plate.
Unfortunately, approach 1. falls over if you use some library that
decides to use pygtk.require().
In the times when I do require a specific version of pygtk then I can
always create a simple wrapper that does the pygtk require stuff.
Now no doubt I’m missing some subtleties as to why it is good to have
these pygtk.require() calls in matplotlib. Is there any way to make
A half-way house would be to do something like this:
import pygtk if not matplotlib.FROZEN and not sys.modules.has_key('gtk'): pygtk.require('2.0')
print >> sys.stderr, sys.exc_info() raise SystemExit('PyGTK version %d.%d.%d or greater is required to
'the GTK Matplotlib backends' % pygtk_version_required)
This code would ensure that the correct pygtk is loaded for people who
haven’t already import’ed gtk without throwing an exception for those
that have loaded gtk prior to importing matplotlib.
The down side with this fix is that it doesn’t help anyone who does
want the pygtk.require() but has made the mistake of importing gtk