import gtk not working on mac

泪湿孤枕 提交于 2019-12-12 04:58:23

问题


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()

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?


回答1:


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

sudo port clean --all -f py27-pygtk

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

port select --list python

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

sudo port select --set python python27

Only then you can install pygtk as follows:

sudo port install py27-pygtk


来源:https://stackoverflow.com/questions/26058539/import-gtk-not-working-on-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!