pygtk导入gtk错误
我下载了 pygtk 中描述的所有内容进行安装。一切都很顺利,直到我尝试输入 "import gtk"
时,它抛出了 ImportError
如下:
from gtk import _gtk
ImportError: DLL load failed: ...(something unreadable)
然后我再次重新安装 pygtk-2.22.0,同样的情况问题是存在的。那么请问该怎么办?提前致谢!
I downloaded everything described as in pygtk for installation. Everything went fine until when I tried to type "import gtk"
, it threw an ImportError
as follows:
from gtk import _gtk
ImportError: DLL load failed: ...(something unreadable)
Then I re-install the pygtk-2.22.0 again, the same problem existed. So what to do please? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您描述的错误通常是由于 python 绑定 (pygtk/pygobject/pycairo) 无法加载正常运行所需的 dll 引起的。大多数这些错误是由以下原因引起的:
关于如何让 pygtk 在 Windows 上运行的建议。请不要更改您的用户
或系统 PATH 环境变量,一体机不再需要它
安装程序。
(最左边)一个与您使用的 pygtk/pygobject/pycairo 版本不兼容。
这就是为什么将 GTK+ 运行时添加到 PATH 环境变量不是一个好主意:
很容易混淆版本(有时 GTK+ 相关安装程序会添加他们的 bin
安装时将目录添加到 PATH,其中包含旧的或不完整的运行时)。
%WINDIR%\system 或 %WINDIR%\sytem32
避免上述 dll 地狱的最直接方法是使用
PyGTK 一体化安装程序 (http://download.gnome.org/binaries/win32/pygtk/2.22/)。
它包含 Python 绑定、GTK+ 运行时甚至 Glade,并且
不再需要您更改 PATH 环境变量。
小警告:如果您决定使用一体化安装程序,则必须卸载
您之前使用过的单独的 pygtk/pygobject/pycairo 软件包(或者您将在
一个充满麻烦的世界...)
The error you describe is usually caused by the python bindings (pygtk/pygobject/pycairo) being unable to load a dll it needs to function properly. Most of those errors are either caused by:
the advice on how to get pygtk working on Windows. Please don't change your user
or system PATH environment variable, it is no longer needed with the all-in-one
installer.
(leftmost) one is not compatible with the pygtk/pygobject/pycairo versions you use.
This is why adding the GTK+ runtime to your PATH environment variable is a bad idea:
it is easy to mix up versions (sometimes GTK+ related installers add their bin
directory to PATH on installation which contains an older or incomplete runtime).
%WINDIR%\system or %WINDIR%\sytem32
The most straightforward way to avoid the dll hell described above is to use the
PyGTK All-in-one installer (http://download.gnome.org/binaries/win32/pygtk/2.22/).
It contains both the Python bindings, the GTK+ runtime and even Glade and does
no longer require you to change the PATH environment variable.
Small warning: if you decide to use the all-in-one installer, you'll have to uninstall
the separate pygtk/pygobject/pycairo packages you've used before (or you'll be in
a world of trouble...)
阅读源代码,也许需要特定版本的 pygtk
编辑源代码以适用于您的 pygtk 版本
read the source code, perhaps there is a need for a specific version of pygtk
edit the source code to work with your pygtk version
我也有这个问题。您在答案中没有明确提及,所以我会建议显而易见的(嗯......对于已经使用了一段时间的人来说可能是显而易见的)。你是用下面三行代码导入的吗?您必须使用这些才能导入 PyGTK。
我假设你的版本和我的一样是 2.24。如果没有,请将其更改为您拥有的版本。
导入 gtk 就足够了。
I had this issue as well. You didn't mention for sure in your answer, so I'll suggest the obvious (well...the obvious to people that have used it a while, perhaps). Did you use the following three lines of code to import? You have to use these, in order, to import PyGTK.
I'm assuming your version here is 2.24 like mine. If not, change it to the version you have.
That should suffice in importing gtk.
问题
正如其他人所指出的,不要将 gtk 放在路径中。我知道,它很诱人,而且它适用于 XYZ,但(至少可以说)它会让人感到困惑。对于像 Linux 这样试图让你变得轻松的平台来说,依赖地狱已经够糟糕的了。
为了澄清起见,PyGTK All In One 为您所做的就是直接在您的 python 包文件夹中安装(看起来是)完整的 gtk+ 运行时,例如在 C:\Python\Lib\site-packages\gtk-2.0\运行时
解决方案
注意:%YOURPYTHONPATH%是一个示例变量,其中包含Python安装的路径(例如C:\ Python,或C:\ Python27,或任何实际的路径)是)。如果您想使用变量来执行此操作,我建议设置%PYTHON_DIR%或%PYTHON_PATH%,因为更多程序可能会使用它。
要让需要 GTK 的 XYZ 程序运行,请在运行程序时将 %YOURPYTHONPATH%\Lib\site-packages\gtk-2.0\runtime\bin 添加到 PATH 中;它需要链接的 DLL 的正确版本位于该文件夹中。我安装的所有其他 GTK+ 运行时 (GTK+/GTK2-Runetime) 都给了我错误。
再次; 不要尝试设置用户或系统级变量(不要打开下图所示的对话框),因为这可能会在以后给您带来问题,除非您非常确定您知道自己是什么正在做。如果您正在阅读本文,您很可能并不像您认为的那样了解。相反,请在 cmd 提示符中更改路径,或使用批处理/脚本文件进行设置。
Problem
As others have noted, don't put gtk in the path. I know, its tempting, and it works for XYZ, but it (to say the least) gets confusing. Dependency hell is bad enough on a platform like Linux which tries to make it easy for you.
For clarification, what the PyGTK All In One does for you is to install (what appears to be) a full gtk+ runtime directly in your python packages folder, so e.g. in C:\Python\Lib\site-packages\gtk-2.0\runtime
Solution
NOTE: %YOURPYTHONPATH% is an EXAMPLE variable which contains the path of your Python installation (e.g. C:\Python, or C:\Python27, or whatever it actually is). I suggest setting %PYTHON_DIR% or %PYTHON_PATH% if you want to use a variable to do this, as more programs are likely to use this.
To get your XYZ program requiring GTK to work, add %YOURPYTHONPATH%\Lib\site-packages\gtk-2.0\runtime\bin to the PATH when running your program; the correct versions of the DLLs it needs to link against are in that folder. All other GTK+ runtimes I had installed (GTK+/GTK2-Runetime) gave me errors.
Again; Do not attempt to set a user or system level variable (don't open up the dialog pictured below) as this will likely cause problems for you later unless you VERY sure you know what you are doing. If you are reading this, you most likely don't know as much as you think you do. Instead, alter the path in a cmd prompt, or use a batch/script file to set it up for you.
安装 pygtk.org 软件包后,按以下顺序安装其中的每一个:
有关详细信息:
http: //freetstar.com/windows7-pygtk-gtk/
我根据电脑上的链接获得了 secuusses。
After you install the pygtk.org package, install each of these in the following order:
For more information:
http://freetstar.com/windows7-pygtk-gtk/
I got the secusses according the link on my PC.