27 December 2010

Making a self contained PyGTK installation

Tired of figuring out dependencies? Me too
PyGTK *could* be easier to install if they adopted the way WxPython or PySide installed, which sadly this is inherently impossible. However I think there is a trick for this!

Look at pygtk.pth under [Python]\lib\site-packages folder, a pth (stand for path?) is read by python interpreter as initialization before user start importing stuff. The idea is inject PATH insertion in pygtk.pth. Note that unlike py file pth file accept only oneliner script like in "python -c" command.

Here is my modified pygtk.pth:
for python 2.7:

gtk-2.0
import sysconfig; pygtkpath=sysconfig.get_path('platlib')
import os; os.putenv("PATH", os.path.join(pygtkpath,"
gtk-2.17.2") + ";" + os.environ["PATH"])
gtk-2.0
import distutils.sysconfig, os; os.putenv('PATH', os.path.join(distutils.sysconfig.get_python_lib(),'gtk-2.17.2;') + os.getenv('PATH'))




Now put GTK runtime in [Python]\lib\site-packages\gtk-2.17.2 and you're done!
note that if you keep bin folder of GTK (not put it outside) then use "gtk-2.17.2/bin" instead of "gtk-2.17.2"

Therefor a true all-in-one installer is possible by put GTK runtime (just the dlls without redundant C devel files) together, maybe one day I'll make one...

No comments:

Post a Comment