1

I just tried to write my first Gtk+ program using python in linux mint with Eclipse + PyDev, but I met this error in PyDev, Unresolved import: Gtk

program source code: http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html

from gi.repository import Gtk win = Gtk.Window() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() 

error shown as below:

enter image description here

Program can run. I checked PYTHONPATH in PyDev, I think it's right. enter image description here

How can I fix this problem?

By the way, could you give some advice about nice free IDE for Python & Gtk+ development in Linux?

4
  • Does it work from the regular Python console? Commented Feb 14, 2013 at 15:54
  • @jadkik94 Yes, it can run in terminal by python command too. Commented Feb 14, 2013 at 16:03
  • From the command line, after importing Gtk see what Gtk.__path__ is and if it's in Pydev's PYTHONPATH. Commented Feb 14, 2013 at 16:26
  • @jadkik94 Gtk.__path__ is /usr/lib/girepository-1.0/Gtk-3.0.typelib I have alread add /usr/lib/girepository-1.0 into PYTHONPATH, but not fix this problem. Commented Feb 14, 2013 at 16:31

3 Answers 3

2

Go to Window->Preferences and add "gi" to "Forced Builtins" (see screenshots).
You should try Glade for GTK3 gui design (see screenshot).
See final result screenshot.
You could also use Sublime Text 3.

enter image description here

enter image description here

enter image description here

enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

this should be the accepted answer, as it actually solves the issue and add code completion.
1

same issue: https://stackoverflow.com/a/11418828/1040891

In Gtk+ 3 Python bindings to binary modules are generated dynamically using *.typelib databases. The dynamic importer for accessing all the modules is located in gi.repository. PyCharm cannot detect these modules using its code insight, because they require special handling.

Note: IPython can detect and handle these modules

1 Comment

Problem is explained, but not solved: what "special handling" the gi.repository modules need to remove the false error mark and enable so autompletion?
1

You must use Python 3.x.

Eclipse->Windows->Preferences->PyDev->Python Interpreter*->Advanced Auto-Config->/usr/share/python3.3**->Ok->Apply->Ok

*If using Python, instead of Jython or IronPython

**If Python 3.3 installed, otherwise try python3, but I've not tested.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.