GTK is awesome. PyGTK is awesome. PyGTK on Windows is far, far less than awesome. I recently wrote some software that runs fine on my Linux box after a couple of apt-gets, but unfortunately the software is for Windows users. I spent a good part of the morning getting all the stuff needed for PyGTK installed in a VM; it was a painful process of trial and error. To save everyone else the trouble, here is how I ended up doing it.
Python 2.5 or 2.6?
I am a 2.6 guy, but if you are using PyGTK on Windows, 2.6 is a bad way to go. As of 2.6, the default compiler for python is VS2008, not MinGW. All of the binaries that are compiled by the gnome groups are done with MinGW, so you can’t actually use these with 2.6 (or at least I couldn’t). It sucks, I know. If you start getting errors like this:
"C:\libs\Python-2.6.1\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 module could not be found.
you need to roll back to 2.5.
Lots of installers
To install PyGTK, run these installers (in this order):
- python-2.5.4.msi
- gtk2-runtime-2.16.0-2009-03-22-ash.exe
- pycairo-1.4.12-2.win32-py2.5.exe
- pygobject-2.14.2-2.win32-py2.5.exe
- pygtk-2.12.1-3.win32-py2.5.exe
Then jump into python and check that it has installed okay:
>>> import gtk
>>>
In case these packages ever go away, I will mirror them here. Happy pythoning!
I tried it, I had python2.6 on windows and gtk was working.
However, since I was unable to find the binary installer for gtksourcview, I rolled back to python2.5.
I have not been able to get gtk to work with python2.5.
I uninstalled all the previous installations of python, and did a clean installation using the exact steps(and binaries) that you mentioned.
HOwever I continue to get the following error
IDLE 1.2.4
>>> import gtk
Traceback (most recent call last):
File “”, line 1, in
import gtk
File “C:\Python25\Lib\site-packages\gtk-2.0\gtk\__init__.py”, line 38, in
import gobject as _gobject
File “C:\Python25\Lib\site-packages\gtk-2.0\gobject\__init__.py”, line 30, in
from gobject.constants import *
File “C:\Python25\Lib\site-packages\gtk-2.0\gobject\constants.py”, line 22, in
from _gobject import type_from_name
ImportError: DLL load failed: The specified procedure could not be found.
I am having the same problem as Srikanth.
I made sure that all prior versions of python, pygtk, pycairo, pygobject, and gtk were uninstalled and that the registry and system variables were reset.
I downloaded the versions you listed and installed them in the order prescribed.
This is the result per python:
IDLE 1.2.4
>>> import gtk
Traceback (most recent call last):
File “”, line 1, in
import gtk
File “C:\Python25\Lib\site-packages\gtk-2.0\gtk\__init__.py”, line 38, in
import gobject as _gobject
File “C:\Python25\Lib\site-packages\gtk-2.0\gobject\__init__.py”, line 30, in
from gobject.constants import *
File “C:\Python25\lib\site-packages\gtk-2.0\gobject\constants.py”, line 22, in
from _gobject import type_from_name
ImportError: DLL load failed: The specified procedure could not be found.
>>> import pygtk
>>> import cairo
>>> import gobject
Traceback (most recent call last):
File “”, line 1, in
import gobject
File “C:\Python25\Lib\site-packages\gtk-2.0\gobject\__init__.py”, line 30, in
from gobject.constants import *
File “C:\Python25\lib\site-packages\gtk-2.0\gobject\constants.py”, line 22, in
from _gobject import type_from_name
ImportError: DLL load failed: The specified procedure could not be found.
>>>
My PATH variable contains a reference to C:\GTK2-Runtime\bin
PYTHONPATH is set to C:\Python25\Lib;C:\Python25\DLLs;C:\Python25\Lib\lib-tk
Any pointers you can give me would be appreciated. I think it is strange that pygtk and cairo would import cleanly, while gtk and gobject would not. I’ve been searching the web for any helpful pointers, but I have not found any as of yet.
Dave
I have some spare time on the weekend; I will try to look into it then.
Hey again guys,
I just did a clean install using my mirrored packages on a fresh windows 7 beta. It worked straight away with no issues and no extra configuration.
>>> import pygtk
>>> import gtk
>>>
If you didn’t use my mirrored packages, try them out. Perhaps the files on the other servers have changed slightly. Sorry I can’t help any further.
Thanks. I will try this.
I also came across a site called portable apps. They have a version of gramps 3.1.1. that runs from a USB drive. While the app does run, I would prefer it to run natively from my laptop. Googling “portable apps” and “gramps” should take you to the site.
Thanks for the help. Worked like a charm.
Doesn’t work for me either:
Traceback (most recent call last):
…
File “my_file.py”, line 5, in
import gtk
File “D:\Programme\Python\lib\site-packages\gtk-2.0\gtk\__init__.py”, line 38, in
import gobject as _gobject
File “D:\Programme\Python\Lib\site-packages\gtk-2.0\gobject\__init__.py”, line 30, in
from gobject.constants import *
File “D:\Programme\Python\lib\site-packages\gtk-2.0\gobject\constants.py”, line 22, in
from _gobject import type_from_name
ImportError: DLL load failed: The specified module could not be found.
Help is appreciated.
btw: I used your mirrowed bundle
Ultrasick,
Maybe try running python from the command line with the verbose flag. So:
python -v
Once it drops you into the interpreter, try importing gtk from there. The problem might show up in the debug output. If you can’t work it out, pastebin and post it here and I will see if I can help.
I had this problem too.
For me, there was usually a pop-up window that gave an error in libglib-2.0-0.dll.
The problem was that there were other folders in my Windows paths (from other applications) that also had this DLL. Python searches the path in forward order and uses the first libglib-2.0-0.dll it finds. There were a lot of old ones there. So, I moved the GTK path entry to the beginning of my path environment var, then tried again and all was well.
It works!
What you have provided is really significant.
I tried to get PyGTK to run several times over the last year or so, and whatever combination I tried, there was an error message.
It’s a pity the Python developers have blocked the possibility of using GTK with newer versions of Python. Or have they? Is it possible to compile current Python with MinGW? (Don’t ask me to try it, I’ve never compiled C in my life
jh,
As I understand it, it is very possible and this is more of an interim bug of sorts.
Yes, it’s a pity (more like a PITA) that pygtk has these issues on Windows.
After some tests, using Python 2.6 and the latest 2.6 versions of pygobject, pycairo and pygtk, this is what I’ve found:
1. The ‘module could not be found” error that’s seen on 2.6 can be worked around (thanks Jeremy) by importing pygtk prior to importing gtk: import pygkt, gtk. Reason: ?? can someone help explain please?
2. I brought over a glade generated program from ubuntu. The glade xml file has a ‘requires gtk version’ line. GtkBuilder on Windows does not parse the ‘requires’ line.
With these workarounds, my little Python program runs fine. Hopefully this can be made less kludgy soon.
Nice post! It’s exactly what I’m looking for. Thanks indeed.
import pygkt
import gtk
Traceback (most recent call last):
File “”, line 1, in
File “H:\Python25\Lib\site-packages\gtk-2.0\gtk\__init__.py”, line 38, in
import gobject as _gobject
File “H:\Python25\Lib\site-packages\gtk-2.0\gobject\__init__.py”, line 30, in
from gobject.constants import *
File “H:\Python25\lib\site-packages\gtk-2.0\gobject\constants.py”, line 22, in
from _gobject import type_from_name
ImportError: DLL load failed: The specified module could not be found.
I have libglib-2.0-0.dll in these folders (on the same drive with Python25):
H:\program files\Avidemux 2.4
H:\apache2triad\mysql\bin
H:\program files\Gtk+\bin
H:\Python25\glade\gtk+-bundle_2.14.7-20090119_win32\bin
Hello friens now i have the same proble…. any one help me…. i did spent a week of time to clear this bug. still not yet. using python2.5 in windows xp
Hello
I have this same problem and I find that win is coping DLL’s to C:/Windows/System32/
When I’ve deleted them from win folder and restart Python it started working !
Of course you have to set env varibles of GTK+ (/bin and /lib)
Guys I have unofficial build if you want.. I have built it to maintain MyPaint windows build.
its here:
http://opensourcepack.blogspot.com/2009/09/pygtk-2160-python-25-win32-unofficial.html
now also for python2.6
zakkum wins. That post got me a lot closer to it working.
Thanks all for your informations.
I am in Windows 2000 Pro.
I tried everything mentioned here :
Uninstall GTK and Python
Install the bundle offered here, in the order prescribed.
Move GTK to the beginning of the path
Removed from the path any application which may have GTK inside
Loaded “import pygtk” before “import gtk”
No effect. I still have this type_from_name error.
I tried the build from zakkum. The error was different becasue the file gobject\__init__.py was different. In both cases this is the first line of this file which causes the problem (import gobject raises the error.
Just in case here is the verbose error :
>>> import pygtk,gtk
# C:\Prog2\Python25\lib\encodings\cp850.pyc matches C:\Prog2\Python25\lib\encodi
ngs\cp850.py
import encodings.cp850 # precompiled from C:\Prog2\Python25\lib\encodings\cp850.
pyc
# C:\Prog2\Python25\lib\site-packages\pygtk.pyc matches C:\Prog2\Python25\lib\si
te-packages\pygtk.py
import pygtk # precompiled from C:\Prog2\Python25\lib\site-packages\pygtk.pyc
# C:\Prog2\Python25\lib\fnmatch.pyc matches C:\Prog2\Python25\lib\fnmatch.py
import fnmatch # precompiled from C:\Prog2\Python25\lib\fnmatch.pyc
# C:\Prog2\Python25\lib\glob.pyc matches C:\Prog2\Python25\lib\glob.py
import glob # precompiled from C:\Prog2\Python25\lib\glob.pyc
import gtk # directory C:\Prog2\Python25\lib\site-packages\gtk-2.0\gtk
# C:\Prog2\Python25\lib\site-packages\gtk-2.0\gtk\__init__.pyc matches C:\Prog2\
Python25\lib\site-packages\gtk-2.0\gtk\__init__.py
import gtk # precompiled from C:\Prog2\Python25\lib\site-packages\gtk-2.0\gtk\__
init__.pyc
import gobject # directory C:\Prog2\Python25\lib\site-packages\gtk-2.0\gobject
# C:\Prog2\Python25\lib\site-packages\gtk-2.0\gobject\__init__.pyc matches C:\Pr
og2\Python25\lib\site-packages\gtk-2.0\gobject\__init__.py
import gobject # precompiled from C:\Prog2\Python25\lib\site-packages\gtk-2.0\go
bject\__init__.pyc
# C:\Prog2\Python25\lib\site-packages\gtk-2.0\gobject\constants.pyc matches C:\P
rog2\Python25\lib\site-packages\gtk-2.0\gobject\constants.py
import gobject.constants # precompiled from C:\Prog2\Python25\lib\site-packages\
gtk-2.0\gobject\constants.pyc
Traceback (most recent call last):
File “”, line 1, in
File “C:\prog2\Python25\Lib\site-packages\gtk-2.0\gtk\__init__.py”, line 38, i
n
import gobject as _gobject
File “C:\Prog2\Python25\lib\site-packages\gtk-2.0\gobject\__init__.py”, line 3
0, in
from gobject.constants import *
File “C:\prog2\Python25\Lib\site-packages\gtk-2.0\gobject\constants.py”, line
22, in
from _gobject import type_from_name
ImportError: DLL load failed: La procÚdure spÚcifiÚe est introuvable.
>>>
Then I installed from the bundle on a computer where nothing running GTK has ever been installed (Windows 2000 Pro with just basic programs) : The same error is present. Incompatibility with Win 2000 Pro ?
Really annoying that the GTK team cannot work on this small issue : What is sure is that it is the module gobject which raises the problem.
Try to comment the block with load_from_name in constants.py, then you get a similar error in the next line of __init__.py from the gobject directory :
>>> import gobject
Traceback (most recent call last):
File “”, line 1, in
File “C:\Prog2\Python25\lib\site-packages\gtk-2.0\gobject\__init__.py”, line 3
1, in
from _gobject import *
ImportError: DLL load failed: La procédure spécifiée est introuvable.
hey all,
I have installed Python 2.6, PyGTK 2.12.1-3, pygobject-2.14.2-2 , pycairo-1.4.12-2 ,GTK+ and I had the same problem. It started working for me when I updated my PATH system variable.The beginning of the variable look like this:
PATH=C:\Program Files\Gtk+\lib;C:\Program Files\Gtk+\bin;C:\Python26\Lib\site-packages\gtk-2.0\gtk
hello jeremy,
what a great man.
thank you for your great help.
thank you.
Hello,
When I try to import gtk in PythonWin, I get the following message:
C:\Python26\lib\site-packages\gtk-2.0\gtk\__init__.py:40: RuntimeWarning: tp_compare didn’t return -1 or -2 for exception
from gtk import _gtk
ImportError: could not import gio
ImportError: could not import gio
I have installed on my Windows Vista machine MinGW, MSYS, PyWin32, I added the binaries for gtk in System Variable, have gcc working on it, and then I installed pycairo, pygobject and pygtk. No problems when I import pygtk but gtk shows the above problem. Any solutions?
Really thanks, I have spent 2 hours trying it . your post really help . very usefull god bless you friend developper!!
Thanks man I had a lot of problems with it and couldn’t find a fix anywhere. Really helped, keep deving.
@Ken
Thnx bro!!!It worked!!
Hi,
Thanks a lot, and being in the same situation, I do agree that developing for Windows users is extremely painful.
I still have one problem though: I need to use poppler (or pypoppler for that matter), is there a set of instructions as easy as yours for that somewhere? So far, all “tutorials” I’ve found were so complicated that they discouraged me from even trying…
Thanks!
Thanks man, it works well! Kisses….