导入gtk在Mac上不起作用 [英] import gtk not working on mac

查看:190
本文介绍了导入gtk在Mac上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python和Mac OS的新手.我已经从macports安装了py27-pygtk-2.24.0_3.
我尝试运行以下命令:

I am new to Python and mac OS. I've Installed py27-pygtk-2.24.0_3 from macports.
I tried to run the following:

#!/opt/local/bin/python2.7
import gtk
window=gtk.Window()
window.connect("destroy", gtk.main_quit)
button=gtk= gtk.Button("Hello")
window.add(button)

window.show_all()\gtk.main()

我正在通过Python启动器执行文件并收到此错误:

I am executing the file through Python Launcher and get this error:

Import error:No module named GTK

我整天都在寻找答案.有人可以帮助我并使它正常工作吗?

I spent the whole day searching for answer. Can someone help me and make it work?

推荐答案

首先,您应该清理所有可能已损坏的pygtk旧安装:

First of all, you should clean up all old installations of pygtk which might be corrupt:

sudo port clean --all -f py27-pygtk

现在,由于系统上已经安装了多个版本的Python,如命令所示:

Now, since you have several versions of Python installed on your system, as shown by the command:

port select --list python

您必须选择macports将安装pygtk的正确计算机,如下所示:

you have to select the correct one into which macports will install pygtk, as follows:

sudo port select --set python python27

只有这样,您才能按如下所示安装pygtk:

Only then you can install pygtk as follows:

sudo port install py27-pygtk

这篇关于导入gtk在Mac上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆