gi.repository search path

I'd like to use PyCharm (on Debian GNU/Linux) to develop a gedit plugin, but there's a bit of a problem with it. It can't resolve `from gi.repository import Gedit` or create stubs for the binary module. I'm pretty sure this is because gedit's gir and typelib files are in gedit-specific directories instead of the system gir and typelib directories. I've tried adding `export GI_TYPELIB_PATH=/usr/lib/x86_64-linux-gnu/gedit/girepository-1.0` to `pycharm.sh` (and confirmed that it's set correctly in a PyCharm terminal) but it doesn't fix the problem.

I also tried symlinking gedit's typelib and gir files to the system directories, but that didn't help either.

Both attempted solutions also cause an exception ending in

`File "/usr/lib/python3/dist-packages/gi/overrides/__init__.py", line 206, in override
    assert g_type != TYPE_NONE`

if I try to import Gedit into a python3 console, so there seems to be some other issue with this module preventing anything other than gedit itself from being able to read it, but seeing as gedit is working AFAICT, its developers might not consider that to be a bug.

Anyone know how to fix this?

1 comment

Hi,

I ran into the same issue and I found workarounds (for Gtk in my case)

pycharm uses a python helper "generator3.py" in order to generate the binary stubs. In my case it's located in /usr/share/pycharm/helpers/generator3.py

You can notice it expects a possible extra path parameter "-s". You may hardcode a specific path to the search path in a dirty way by adding manually the directories where the typelib files are located. (Of course that's very dirty)

In my case I wanted: sys.path.append('/usr/lib/girepository-1.0') (gist example)

Otherwise you may also start pycharm with a particular PYTHONPATH. I was able to find this out by reading how the "-s" parameter value is generated. See extraSyspath in PySkeletonGenerator.java.

Example: PYTHONPATH=/usr/lib/girepository-1.0 pycharm .

I don't know yet if there's a way to set this extraSyspath from the IDE

Cheers,

Pierre

---

You may need to clear ~/.PyCharmCE2018.1/system/python_stubs to see the effect of you changes. In particular to realize that your changes don't work anymore, because once the stubs are generated they are reused subsequently even if pycharm is not able to generate the stubs anymore

.

0

Please sign in to leave a comment.