问题
I can import gtk
without any problem previously. I made a GUI in glade for GTK+ 3. Then I thought that I would like to try GTK+ 3. So I installed PyGObject. I later found out that PyGObject has little documentation and I'm using Windows (makes things worse I know).
The problem is here, I can't use import gtk
anymore. Neither can I use from gi.repository import Gtk
. I've tried installing PyGTK bundle again but it doesn't help.
>>> import gtk
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import gtk
File "C:\Python27\lib\site-packages\gtk-2.0\gtk\__init__.py", line 30, in <module>
import gobject as _gobject
File "C:\Python27\lib\site-packages\gtk-2.0\gobject\__init__.py", line 26, in <module>
from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
File "C:\Python27\lib\site-packages\gtk-2.0\glib\__init__.py", line 22, in <module>
from glib._glib import *
ImportError: DLL load failed: The specified procedure could not be found.`
回答1:
This looks like C-level library is missing, or at least in a place where the Python wrappers can't find it. Try re-installing whichever version of the C library corresponds to which Python library you would like to use (GTK2 and GTK3 should, theoretically, be parallel installable, but that installing the newer PyGobject broke import gtk
suggests that at least these particular bindings aren't for some reason).
来源:https://stackoverflow.com/questions/13794658/unable-to-import-gtk-after-installing-pygobject