3

I'm learning python + gtk3+ so I was looking for an IDE to help me. Is there any way to get code completion with PyGObject? I've really tried EVERYTHING I can think of. I have pycharm build 138.2401 where this bug: https://youtrack.jetbrains.com/issue/PY-6932 is supposed to be fixed but I can't get any code suggestions. This simple code would raise a warning (Gtk is not found):

#!/usr/bin/python3
from gi.repository import Gtk

Also, using fakegir doesn't work either (and it does work with WingIDE). Here is my project start script in case I'm doing something (horribly) wrong:

import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
sys.path.append(self,"/home/obok/.cache/fakegir/")
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
  • Project startup script isn't relevant, I don't think pycharm looks at your `sys.path` code. – simonzack Sep 24 '14 at 18:23
  • That rises other question then: How do I add a folder to the PYTHONPATH in pycharm? Thanks. – user2329051 Sep 24 '14 at 18:33
  • It's in `Settings`, `Project Structure`, `Content Root`. – simonzack Sep 24 '14 at 18:40
  • Well, that got me code completion but now the project doesn't run from pycharm, it does in terminal :/ . I think it has something to do with (fakegir readme) :" By default the package is saved in ~/.cache/fakegir/. This is the directory you want to add to your Python PATH. Of course, you shouldn't put this package in your global PYTHONPATH or your PyGObject applications will stop working immediatly ;)" – user2329051 Sep 24 '14 at 19:12

2 Answers2

2

Using the page you suggested, I tested the solution at the bottom of the page, and guess what, it worked! It took some indexing from Pycharm, but everything now autocompletes!

Just write:

from gi.repository import Gtk

Then press alt+enter, and select "Generate stubs for binary module"

Hadrien Titeux
  • 450
  • 2
  • 11
2

2020 Fix

will post a fix here that works for me it might help someone

pycharm version: 2020.1 community

os: Manjaro kde

project interpreter: python 3.8 system wide "not a virtual env"

Gtk completion is working only from pycharm terminal, but not from editor area

the proposed solution of putting mouse pointer at Gtk keyword and Then press alt+enter, simply doesn't work because it didn't show option "Generate stubs for binary module"

solution Steps:

  1. Change this line in idea.properties file to idea.max.content.load.filesize=20000, in may case i used sudo nano /usr/share/pycharm/bin/idea.propertie to edit this file, yours might be in different place, use locate or find cmd to findout.
  2. create a vertual env from pycharm for your current project.
  3. Install Gtk: follow the exact steps in official website here otherwise it will fail, you might need to install package "wheel" into your venv
  4. After finish installing successfully, click on Gtk in from gi.repository import Gtk then press alt+enter, and select "Generate stubs for binary module".
  5. wait.......... until finished.
  6. pycharm will complain there is no type hint for Gtk and offer to install "PyGobject-stubs" DON'T install it, because it cause problem.
  7. After all done ... restart Pycharm.
  8. Pycharm will start but will take some more time again for indexing and finally all work.
Mahmoud Elshahat
  • 1,873
  • 10
  • 24