windows pygtk 导入 gtk 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4179425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pygtk import gtk error
提问by ladyfafa
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:
我下载了pygtk 中描述的所有内容进行安装。一切都很顺利,直到我尝试输入时"import gtk"
,它抛出了ImportError
如下:
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!
然后我再次重新安装pygtk-2.22.0,同样的问题存在。那请问该怎么办?提前致谢!
回答by dieterv
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:
您描述的错误通常是由 python 绑定 (pygtk/pygobject/pycairo) 无法加载正常运行所需的 dll 引起的。大多数错误是由以下原因引起的:
- the GTK+ runtime not being on your PATH environment variable. This has long been 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.
- multiple GTK+ runtime versions are on your PATH environment variable and the first (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).
- a rare case where some software package installed libintl.dll and iconv.dll into %WINDIR%\system or %WINDIR%\sytem32
- GTK+ 运行时不在您的 PATH 环境变量中。这一直是关于如何让 pygtk 在 Windows 上工作的建议。请不要更改您的用户或系统 PATH 环境变量,多合一安装程序不再需要它。
- 多个 GTK+ 运行时版本位于您的 PATH 环境变量中,第一个(最左边的)版本与您使用的 pygtk/pygobject/pycairo 版本不兼容。这就是为什么将 GTK+ 运行时添加到您的 PATH 环境变量是一个坏主意:很容易混淆版本(有时 GTK+ 相关安装程序在安装时将其 bin 目录添加到 PATH 中,其中包含旧的或不完整的运行时)。
- 一些软件包将 libintl.dll 和 iconv.dll 安装到 %WINDIR%\system 或 %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.
避免上述 dll 地狱的最直接方法是使用 PyGTK 多合一安装程序 (http://download.gnome.org/binaries/win32/pygtk/2.22/)。它包含 Python 绑定、GTK+ 运行时甚至 Glade,并且不再需要您更改 PATH 环境变量。
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/pygobject/pycairo 软件包(否则您将陷入困境......)
回答by CodeMouse92
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.
我也有这个问题。您在回答中没有明确提及,所以我会建议显而易见的(好吧......对于已经使用它一段时间的人来说很明显,也许)。你是用下面三行代码导入的吗?您必须使用这些来导入 PyGTK。
I'm assuming your version here is 2.24 like mine. If not, change it to the version you have.
我假设你这里的版本和我的一样是 2.24。如果没有,请将其更改为您拥有的版本。
import pygtk
pygtk.require('2.24')
import gtk
That should suffice in importing gtk.
这应该足以导入 gtk。
回答by smaudet
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.
正如其他人所指出的,不要将 gtk 放在路径中。我知道,它很诱人,而且适用于 XYZ,但它(至少可以说)令人困惑。依赖地狱在像 Linux 这样的平台上已经够糟糕了,它试图让你轻松。
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
为了澄清起见,PyGTK All In One 为您所做的是直接在您的 python 包文件夹中安装(看起来是)完整的 gtk+ 运行时,例如在 C:\Python\Lib\site-packages\gtk-2.0\运行
Solution
解决方案
NOTE: %YOURPYTHONPATH% is an EXAMPLEvariable 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.
注意:%YOURPYTHONPATH% 是一个EXAMPLE变量,它包含你的Python 安装路径(例如C:\Python 或C:\Python27,或者它实际上是什么)。如果您想使用变量来执行此操作,我建议设置 %PYTHON_DIR% 或 %PYTHON_PATH% ,因为更多程序可能会使用它。
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.
要让需要 GTK 的 XYZ 程序运行,请在运行程序时将%YOURPYTHONPATH%\Lib\site-packages\gtk-2.0\runtime\bin 添加到 PATH 中;它需要链接的 DLL 的正确版本位于该文件夹中。我安装的所有其他 GTK+ 运行时(GTK+/GTK2-Runetime)都给了我错误。
Again; Do notattempt 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.
再次; 不要不尝试设置一个用户或系统级变量(不打开如下图所示的对话框),因为这很可能会造成以后对你的问题,除非你非常确定你知道自己在做什么。如果您正在阅读本文,那么您很可能并不像您认为的那么了解。相反,在 cmd 提示中更改路径,或使用批处理/脚本文件为您设置。
回答by ebal
read the source code, perhaps there is a need for a specific version of pygtk
阅读源代码,也许需要特定版本的pygtk
edit the source code to work with your pygtk version
编辑源代码以使用您的 pygtk 版本
回答by Jimmy
After you install the pygtk.org package, install each of these in the following order:
安装 pygtk.org 包后,按以下顺序安装其中的每一个:
- pycairo-1.8.6.win32-py2.6.exe
- pygobject-2.20.0.win32-py2.6.exe
- pygtk-2.16.0+glade.win32-py2.6.exe
- gtk+-bundle_2.16.6-20100912_win32.zip
- pycairo-1.8.6.win32-py2.6.exe
- pygobject-2.20.0.win32-py2.6.exe
- pygtk-2.16.0+glade.win32-py2.6.exe
- gtk+-bundle_2.16.6-20100912_win32.zip
For more information:
想要查询更多的信息:
http://freetstar.com/windows7-pygtk-gtk/
http://freetstar.com/windows7-pygtk-gtk/
I got the secusses according the link on my PC.
我根据我电脑上的链接得到了 secusses。