问题
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