Lesen

Distributing PyGTK and GTK on Windows

Geschrieben am 2010-07-17 07:26:03

Okay, so I write a lot of GUI software with Python for personal use or interest, always being run at my Debian GNU/Linux box.

But this time I've done a commercial thing for a group of people, and of course I used Python and PyGTK – with the fact in mind, that distribution will be nearly like hell.

The main problem is distributing the GTK binaries (making an exe out of your Python scripts can be easily done with py2exe, also with PyGTK – there're pages on the web explaining how), because unfamiliar guys may be really disappointed by at least two facts:

So for easy distribution, we strongly have to sort those things out. At first remove all the files that are not needed by a customer, namely GTK headers, documentation, examples, import libraries... If I remember correctly, only bin/ and etc/ were left on my side, reducing the size to ~9 MiB.

Secondly, it would be nice if we were able to distribute the GTK binaries directly with the program, without the need to install anything (you know, installing stuff on Windows is always considered evil). Python looks at PATH when loading modules, so we have to make sure the distributed GTK binaries will be found.

This little hack will do it:

import os, os.path
if os.name == "nt":
	os.environ["PATH"] += ";" + os.path.join( os.getcwd(), "gtk", "bin" )

There you go, Python will now also look in the gtk/bin/ subdirectory of your project. Done!