You are not logged in.
Hi,
I wanna enjoy with python gtk+ toolkit.
I try run this code:
#!/usr/bin/python
from gi.repository import Gtk
Gtk.init(None)
Hello=Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, "Hello world!")
Hello.format_secondary_text("This is an example dialog.")
Hello.run()
from wiki and I get errors:
Traceback (most recent call last):
File "./gtk1.py", line 2, in <module>
from gi.repository import Gtk
File "/usr/lib/python3.2/site-packages/gi/repository/__init__.py", line 25, in <module>
from ..importer import DynamicImporter
File "/usr/lib/python3.2/site-packages/gi/importer.py", line 24, in <module>
import logging
File "/usr/lib/python3.2/logging/__init__.py", line 27, in <module>
from string import Template
ImportError: cannot import name Template
I'm little n00b in python, and I need help If it's important I am using geany.
anyway this code in c++ works pretty good.
Last edited by xorgx3 (2012-05-23 19:37:52)
Offline
I'm a lot n00b in python. That said, my suggestion would be to try the command that failed (from string import Template) directly in the python interpreter. If you get the error there, relaunch the interpreter with extra verbosity and run the command again; maybe it will help you figure out what's wrong.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
I'm surprised because it working in python interpreter. I don't know why not working in any IDE (geany and eric).
Offline
@xorgx3: Is there a file named "string.py" in the current directory? If yes, remove it along with "string.pyc" and try again. Otherwise run the script again with "python -v" as suggested by alphaniner.
Offline
Oh, How You know this? Now it working very well. Why this file was a problem?
Anyway very thanks man.
Offline
To explain lunar's solution:
If you have a python file named string (string.py or string.pyc) in your current directory, python will try to import from that file rather than its proper libraries.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
You are great! Very thanks for help!
SOLVED!
Offline