Reputation:
In my source code I have:
import gtk
But when I run the script with python3 script.py command I get the following error. What package should I install to get it working?
Edit: my bad. here is the error:
ImportError: No module named gtk
Edit2: Thanks for the answer, kaizer.se. But I'm still getting an error message. Take a look at the following code: import pygtk, gtk pygtk.require('2.0')
def main():
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
s = u"привет 한국"
win.set_title(s)
win.connect("destroy", gtk.main_quit)
win.show()
if __name__ == "__main__":
main()
gtk.main()
When I run this script I get the following error:
SyntaxError: Non-ASCII character '\xd0' in file basics.py on line 6, but no encoding declared; see python.org/peps/pep-0263.html for details
Any idea how I may solve this problem? Thanks.
Upvotes: 0
Views: 358
Reputation: 49803
There is no big difference between how Python 3 and Python 2.6 handle unicode and international text, technically. The biggest difference is what the classes are called and what the defaults are.
So if you in Python 3 write:
s = "Grüß Gott"
you take this in Python 2.x:
# coding: UTF-8
s = u"Grüß Gott"
PyGTK always works with the UTF-8 encoding internally, and you can pass it unicode strings or UTF-8-encoded strings however you want.
The best model is to always work with unicode strings internally, and always convert strings as soon as they enter your program (say, you read a file). Again, in Python 3 this is more explicitly enforced, but the process is really exactly the same.
Addessing the updated question: I have already answered, Look closely at my Py 3 and Py 2.x examples! Hint: You must specify an encoding on the first line of every file, like this: # coding: UTF-8
You must also ask yourself, Baha, when you see an error message like this:
SyntaxError: Non-ASCII character '\xd0' in file basics.py on line 6, but no encoding declared; see python.org/peps/pep-0263.html for details
Did you read the message and see it says "no encoding declared"? Did you follow the link and read the information there? It would have been easy to solve this yourself.
Upvotes: 0
Reputation: 41306
PyGtk doesn't support Python 3 yet. You might want to use Python 2.x and then you will need to install the python-gtk2
package.
Upvotes: 1