I notice that pygtk.require('2.0') calls have appeared in
backend_gtk.py and backend_gdk.py
It has not appeared, its been used since matplotlib 0.53 at least,
probably forever.
I am not convinced that library code should include calls to
pygtk.require()
>
The problem is that pygtk.require() has to be called >before<
importing gtk.
>
This means that if you are using gtk then you have two choices:
> 1. never use pygtk.require()
> 2. 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
them optional?
>
A half-way house would be to do something like this:
>
try:
import pygtk
if not matplotlib.FROZEN and not sys.modules.has_key('gtk'):
pygtk.require('2.0')
except:
print >> sys.stderr, sys.exc_info()[1]
raise SystemExit('PyGTK version %d.%d.%d or greater is required to
run '
'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
first.
>
Any thoughts?
>
John
I've never liked pygtk.require(), it tries to be clever by editing your
sys.path to solve one problem, but creates other problems like you describe,
so on balance you don't gain much, if anything.
The only situation it helps with is when you have pygtk 1 and 2 installed on
the same system AND pygtk 1 is ahead of pygtk 2 in sys.path. I think that is
increasing rare nowadays.
My vote is to remove it completely.
Steve
Send instant messages to your online friends http://au.messenger.yahoo.com
···
On Thu, 2005-07-14 at 10:52 -0700, matplotlib-users-request@lists.sourceforge.net wrote: