Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

python - PyCharm can not resolve PyGObject 3.0, but code runs fine

I'm using PyCharm 2.5 on Ubuntu 11.10, trying to develop an application using PyGObject 3.0 on Python 3.2.2. I've installed the Ubuntu package python3-gobject, and when I run my code, it works exactly as expected.

However, PyCharm can not seem to find any of the PyGObject modules. It says Unresolved refrence: 'Gtk' when I hover over Gtk in my import statement, and of course none of the auto-completion works.

This is my code:

#!/usr/bin/env python3

from gi.repository import Gtk

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

I've even tried making a python virtual environment and then installing PyGObject from source into it, and then even tried making symlinks from all the .py files in site-packages/gi/overrides to site-packages/gi/repository, all with no luck.

Any advice would be greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Position the text cursor inside the redlined Gtk in:

from gi.repository import Gtk

hit Alt + Enter and choose "Generate stubs for binary module"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...