How do I install PyGTK / PyGobject on Windows with Python 2.6?

lfaraone picture lfaraone · Aug 18, 2009 · Viewed 24.9k times · Source

I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute import gobject I get this:

Traceback (most recent call last):
    import gobject
  File "C:\Python26\lib\site-packages\gtk-2.0\gobject\__init__.py", line 30, in <module>
    from gobject.constants import *
  File "C:\Python26\lib\site-packages\gtk-2.0\gobject\constants.py", line 22, in <module>
    from _gobject import type_from_name
ImportError: DLL load failed: The specified procedure could not be found.

This appears to be caused by the switch from building using MinGW to Microsoft Visual Studio, as documented Python Bug 3308 (closed: wontfix).

Is there any way to install PyGTK/PyGObject in a way that will work with Python 2.6 on Windows, without having to recompile one or the other from source?

Answer

ewall picture ewall · Aug 18, 2009

I have it working fine, and it didn't give me much trouble, so we know it can be done...

Keep in mind you will probably need all of the following installed on your Windows machine:

I suspect in your case that the PyGTK libraries are not finding your GTK+ Runtime directory where the DLLs are. You should have the environment variable GTK_BASEPATH set to the directory of your GTK+ Runtime (usually C:\GTK).

Please also see the PyGTK-on-Windows FAQ

Now, if you're trying to compile the PyGTK'ed Python with Py2EXE, that's a bit more complicated, but it can be done as well...