PyCharm can not resolve PyGObject 3.0, but code runs fine
Asked Answered
W

2

29

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!

Wahlstrom answered 10/7, 2012 at 16:39 Comment(0)
D
33

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.

I've filed a feature request for this issue: PY-6932. Feel free to vote for it.

Deuced answered 10/7, 2012 at 17:37 Comment(5)
Ah, PyGObject is very fancy indeed. Voted for your feature, maybe we can have it some day! :DWahlstrom
Also, would any other IDE support this? I'm about to develop a moderate-sized GTK+ 3 application and would love to have a good IDE to use for it. What would this feature be called so that I can search for it?Wahlstrom
You could use bpython or bpython3Acolyte
The issue is fixed. From the support, it says: "hit Alt + Enter on from gi.repository import Gt<caret>k and choose "Generate stubs for binary module" " and it worked!Redmon
Please update your answer with solution at: https://mcmap.net/q/478451/-pycharm-can-not-resolve-pygobject-3-0-but-code-runs-fineHuggins
P
61

Position the text cursor inside the redlined Gtk in:

from gi.repository import Gtk

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

Proudlove answered 11/11, 2015 at 8:17 Comment(0)
D
33

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.

I've filed a feature request for this issue: PY-6932. Feel free to vote for it.

Deuced answered 10/7, 2012 at 17:37 Comment(5)
Ah, PyGObject is very fancy indeed. Voted for your feature, maybe we can have it some day! :DWahlstrom
Also, would any other IDE support this? I'm about to develop a moderate-sized GTK+ 3 application and would love to have a good IDE to use for it. What would this feature be called so that I can search for it?Wahlstrom
You could use bpython or bpython3Acolyte
The issue is fixed. From the support, it says: "hit Alt + Enter on from gi.repository import Gt<caret>k and choose "Generate stubs for binary module" " and it worked!Redmon
Please update your answer with solution at: https://mcmap.net/q/478451/-pycharm-can-not-resolve-pygobject-3-0-but-code-runs-fineHuggins

© 2022 - 2024 — McMap. All rights reserved.