导入 GTK 时出错

发布于 2024-11-25 11:18:21 字数 419 浏览 5 评论 0 原文

我正在运行 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。

I'm running Python 2.7, with the latest version of GTK installed.

I'm trying to import gtk with the following line of code:

import gtk

It is throwing the following error:

Traceback (most recent call last): File
"C:\GTKTutorial\tutorial.py", line 3, in
import gtk File
"C:\Python27\lib\site-packages\gtk-2.0\gtk__init__.py", line 40, in

from gtk import _gtk ImportError: DLL load failed: The specified
procedure could not be found.

How do I fix this? import pygtk is working, and I have Glade 3.8.0 installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若水般的淡然安静女子 2024-12-02 11:18:21

我刚刚花了三天时间在我的电脑上调试这个问题。这个问题可能有很多根本原因,因为导入 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文