简体   繁体   English

如何在python2.7中安装gtk?

[英]How to install gtk in python2.7?

I'm using Debian 6.04 and Python 2.7 我正在使用Debian 6.04和Python 2.7
I compiled Python 2.7 ,(./configure,make,make install) 我编译了Python 2.7,(。/ configure,make,make install)
in the console: 在控制台中:

>python2.7  
Python 2.7.3 (default, Jul 28 2012, 16:54:06) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named gtk

How do I install gtk in Python 2.7? 如何在Python 2.7中安装gtk?

In Python 2.6: 在Python 2.6中:

tiger@debian:~$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtk
>>> import pygtk
>>> import gobject

Try installing it using pip/python-pip/easy_install. 尝试使用pip / python-pip / easy_install安装它。 On Fedora I installed it like this: 在Fedora上我安装它是这样的:

sudo pip install PyGTK

I would normaly create a virtualenv based on python 2.7 using 我会正常地创建一个基于python 2.7使用的virtualenv

$ virtualenv -p /usr/bin/python2.7 .

and then install your package inside the virtualenv. 然后在virtualenv中安装你的包。

However, pygtk is an awkward exception: it can only be install through PyPI on a Windows platform, because some of its dependencies (for the Posix version) are not available of PyPI. 但是, pygtk是一个尴尬的例外:它只能在Windows平台上通过PyPI安装,因为它的某些依赖项(对于Posix版本)不能用于PyPI。

On Debian, install the PyGTK package system-wide with 在Debian上,安装系统范围内的PyGTK软件包

$ sudo pip install PyGTK

For Windows: 对于Windows:

pip install PyGTK

For MacOS: 对于MacOS:

brew install pygtk
  • note that this works out of the box with the brew-installed python2 (for me, that's in /usr/local/Cellar/python\\@2/2.7.15/bin/python2.7 ). 请注意,这与使用brew安装的python2开箱即用(对我来说,这是在/usr/local/Cellar/python\\@2/2.7.15/bin/python2.7 )。 In order to use it with python installed by other means make sure you append PYTHONPATH. 为了通过其他方式安装python使用它,请确保附加PYTHONPATH。

For Ubuntu: (to work with the system-installed python2) 对于Ubuntu :(使用系统安装的python2)

sudo apt-get install python-gtk2-dev

Conda: 康达:

conda install -c ostrokach gtk
  • if you have python2 running in a conda environment. 如果你在conda环境中运行python2。

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

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