导入 GTK 时出错
我正在运行 Python 2.7,并安装了最新版本的 GTK。
我尝试使用以下代码行导入 gtk:
import gtk
它抛出以下错误:
回溯(最近一次调用最后一次):文件 “C:\GTKTutorial\tutorial.py”,第 3 行,在 导入 gtk 文件 “C:\Python27\lib\site-packages\gtk-2.0\gtk__init__.py”,第 40 行,在 from gtk import _gtk ImportError: DLL 加载失败: 指定的 找不到程序。
我该如何解决这个问题? import pygtk 正在工作,并且我安装了 Glade 3.8.0。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您从哪里获得 PyGTK 安装程序?尝试使用这个:http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/pygtk-all-in-one-2.22.6.win32-py2.7.msi
Where did you get the PyGTK installer from? Try using this one: http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/pygtk-all-in-one-2.22.6.win32-py2.7.msi
我刚刚花了三天时间在我的电脑上调试这个问题。这个问题可能有很多根本原因,因为导入 gtk 实际上会导致加载大量 DLL。如果其中任何一个失败,您都会收到相同的错误消息。对我来说,突破是
http://www.dependencywalker.com/
我用它来分析命令
python -i -c "import gtk"
在我的电脑上,system32 目录中存在错误版本的 zlib1.dll,这导致 gtk\bin 中的正确版本无法加载。即使我的路径中的第一个条目指向 gtk\bin,它仍然这样做。
我从 system32 中删除了 zlib1.dll(将其放在那里的应用程序应该死掉)并且导入工作正常。您的问题可能有所不同,但依赖步行器可能可以给您提示,说明出了什么问题。
除了您放置在目录或路径中的原因之外,Windows 还可能出于其他原因加载 DLL。我找到了博客
http://www.davidlenihan.com/2007/07/winsxs.html有用
。它描述了 Microsoft 用于管理许多版本 DLL 的解决方案,以及如何解决问题。
I just spent 3 days debugging this issue on my computer. This problem can have many root causes because importing gtk actually causes a lot of DLLs being loaded. If any of them fails, you get the same error message. For me, the break-through was
http://www.dependencywalker.com/
which I used to profile the command
python -i -c "import gtk"
On my PC, a wrong version of zlib1.dll was in the system32 directory, which prevented the right one in gtk\bin from loading. And it did that even though the first entry in my path pointed to gtk\bin.
I deleted the zlib1.dll from system32 (the application that put it there deserves to die) and the import worked fine. Your problem may be different, but dependency walker probably can give you a hint on what is going wrong.
Windows can have other reasons for loading a DLL other than the one you put in your directory or path. I found the blog
http://www.davidlenihan.com/2007/07/winsxs.html
useful. It describes Microsoft's solution for managing many versions of DLLs, and how to troubleshoot problems with it.