简体   繁体   English

在python 2.7(win 32)中没有名为pygtk的模块,但肯定已安装

[英]No module named pygtk in Python 2.7 (win 32) but it's definitely installed

I have installed a number of python packages using a mix of setup.py install and pip install from the command line. 我已经从命令行使用setup.py install和pip install的混合安装了许多python软件包。 I can successfully import all of these into IDLE. 我可以将所有这些成功导入IDLE。 I am running Python 2.7.9 (win32 on a win64 machine). 我正在运行Python 2.7.9(在win64计算机上为win32)。

I installed pygtk 2.22 using pip install--exactly the same as about half a dozen other packages. 我使用pip install安装了pygtk 2.22-与大约六个其他软件包完全相同。 But I now cannot import it into IDLE (import pygtk all lowercase) and get the typical "No module named pygtk" error. 但是我现在无法将其导入IDLE(全部导入小写的pygtk),并得到典型的“无模块名为pygtk的错误”。 I checked using pip.get_installed_distributions() and it is listed. 我使用pip.get_installed_distributions()检查并列出了它。

Any help? 有什么帮助吗?

OK, I think I have one solution for anyone looking for a way to get pygtk: 好的,我想对于任何寻求获取pygtk方法的人都有一个解决方案:

Get the executable from http://www.www.pygtk.org (I previously used the whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip - these mostly seem pretty good but no luck for me in this case). 获得从可执行http://www.www.pygtk.org (我以前使用从WHL http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip -这些大多是看起来不错,但没有运气在这种情况下对我来说)。 I used pygtk-2.24.0.win32-py2.7.exe to match my system. 我使用pygtk-2.24.0.win32-py2.7.exe来匹配我的系统。

Follow FLIR31207's excellent instructions regarding adding to the system path. 请遵循FLIR31207关于添加系统路径的出色说明。 For me this was: 对我来说是:

import sys
sys.path.append("C:\Python27\Lib\site-packages\gtk-2.0")

import pygtk will still throw an error, but a different error (which I can't now reproduce because I fixed it). import pygtk仍然会引发错误,但是会引发不同的错误(由于我已将其修复,因此现在无法重现)。 Something like missing pygobject. 像缺少pygobject之类的东西。

Turns out pygtk has dependencies. 原来pygtk具有依赖项。 Back to pygtk.org to get PyCairo and PyGObject executables and install these as well. 返回pygtk.org以获取PyCairo和PyGObject可执行文件并安装它们。

import pygtk and no error. 导入pygtk,没有错误。 I think that's it. 我想就是这样。 Thanks FLIR31207! 感谢FLIR31207!

If you import a module with import modulexyz Python searches for a file called modulexyz in 如果使用import modulexyz导入模块,Python将在以下位置搜索名为modulexyz的文件

  • the current folder 当前文件夹
  • all folders in sys.path sys.path所有文件夹

If pygtk.py is not in one of those, it cannot be imported with a simple import pygtk . 如果pygtk.py不在其中之一中,则无法使用简单的import pygtk I suggest doing the following: 我建议您执行以下操作:

  • run python 运行python
  • in this interactive Python session run 在此交互式Python会话中运行
    • import sys
    • print sys.path

This will print a (long) list of folders where Python will look for modules; 这将打印一个(长)文件夹列表,Python将在其中查找模块。 if the pygtk.py cannot be found in one of those, you can add it to sys.path before importing the module: 如果在其中之一中找不到pygtk.py,则可以在导入模块之前将其添加到sys.path

import sys
sys.path.append(folder_where_pygtk.py_is_located)
import pygtk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM