[pygtk] pygtk.require("2.0") changed sys.path[0]

Paul Pogonyshev pogonyshev at gmx.net
Mon Mar 19 07:02:04 WST 2007


Preben Randhol wrote:
> Hi
> 
> If I do:
> 
> try:
> 	import pygtk
> 	pygtk.require("2.0")
> except:
> 	pass
> 
> then sys.path[0] will point towards 
> /usr/lib/python2.4/site-packages/gtk-2.0
> in stead of the script. Is this expected behavior?

Yes, I think.  require() above changes sys.path so that correct GTK+
version (2.0 in your case) is loaded.

> If so is there an alternative to sys.path[0] except from catching it
> before doing pygtk.require. Do one need to do this at all by the way?

There is no alternative I think.  But most of the time you don't need
to worry.  If you do, however, better copy it to some meaningfully
named variable like

	path_to_application = sys.path[0]

before doing anything else.

Paul


More information about the pygtk mailing list