Error initializing Python Plugin Loader

Asked by Bob Cargill

Using Ubuntu 18.04 and gedit 3.28.1. Installed gedit-plugins via Synaptic.
When attempting to activate the plugins, the plugins failed with the following errors on the command line:

    (gedit:17930): libpeas-WARNING **: 13:51:56.452: Error initializing Python Plugin Loader: PyGObject initialization failed
    ImportError: could not import gobject (error was: ModuleNotFoundError("No module named 'gi'",))

    (gedit:17930): libpeas-WARNING **: 13:51:56.452: Please check the installation of all the Python related packages required by
    libpeas and try again

    (gedit:17930): libpeas-WARNING **: 13:51:56.452: Loader 'python3' is not a valid PeasPluginLoader instance

Ubuntu 18.04 comes with ptyon3 as the default python. It also has python 2.7 installed. I also have Anaconda installed in my user space with python 3.6.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gedit-plugins Edit question
Assignee:
No assignee Edit question
Solved by:
Bob Cargill
Solved:
Last query:
Last reply:
Revision history for this message
Bob Cargill (rsc-bioeng) said :
#1

Here is how I solved the problem:
When running python3, it could not import gi:

:~$ python3
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gi'
>>> import sys
>>> for i in sys.path: print(i)
...

/home/bob/code
/home/bob/anaconda3/lib/python36.zip
/home/bob/anaconda3/lib/python3.6
/home/bob/anaconda3/lib/python3.6/lib-dynload
/home/bob/anaconda3/lib/python3.6/site-packages
>>>

However, running python3 as root (sudo python3), I could import gi:

:~$ sudo python3
[sudo] password for bob:
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> import sys
>>> for i in sys.path: print(i)
...

/usr/lib/python36.zip
/usr/lib/python3.6
/usr/lib/python3.6/lib-dynload
/usr/local/lib/python3.6/dist-packages
/usr/lib/python3/dist-packages
>>>

Note that Anaconda's python does not search the system's distribution packages. The gi package is installed in /usr/lib/python3/dist-packages, so user-space python3 can't find it and the plugins don't load. To solve the problem for Anaconda, you can add a file in the /home/bob/anaconda3/lib/python3.6/site-packages directory that points to the system distribution. Here's how I did it (following this post: <https://stackoverflow.com/questions/37006114/anaconda-permanently-include-external-packages-like-in-pythonpath>):

echo /usr/lib/python3/dist-packages > /home/bob/anaconda3/lib/python3.6/site-packages/dist-package.pth

This will append the distribution packages directory to the python search path and the gi package will be found in user space.
After the addition of the path file in local python3, import gi works without issue:

:~$ python3
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for i in sys.path: print(i)
...

/home/bob/code
/home/bob/anaconda3/lib/python36.zip
/home/bob/anaconda3/lib/python3.6
/home/bob/anaconda3/lib/python3.6/lib-dynload
/home/bob/anaconda3/lib/python3.6/site-packages
/usr/lib/python3/dist-packages
>>> import gi
>>>

I imagine that this will work for others who have installed a local python3 version in their home directory and are having this problem.

Note: sorry for the poor formatting. I don't know how to add codes to pretty this up nor whether they even exist.