Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import name '_gi'

Tags:

python

pi

ubuntu

I'm trying to add a repository to ppa with the add-apt-repository commands but the _gi module from Python is not found.

I did this command : sudo add-apt-repository ppa:s-mankowski/ppa-kf5

Here is the traceback :

Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 11, in <module>
    from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 67, in <module>
    from gi.repository import Gio
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)

I'm on Ubuntu with Python3.7, I tried many solutions like but it doesn't work :

$ cd /usr/lib/python3/dist-packages
$ sudo ln -s apt_pkg.cpython-{36m,37m}-x86_64-linux-gnu.so

$ cd /usr/lib/python3/dist-packages/gi
$ sudo ln -s _gi.cpython-{36m,37m}-x86_64-linux-gnu.so

I can't use the sudo add-apt-repository ppa:s-mankowski/ppa-kf5 command but running a Python file with python3 {file} works.

Thanks for the help !

like image 247
Hugo Sohm Avatar asked Dec 18 '19 10:12

Hugo Sohm


4 Answers

Thanks to a comment by Wilhelm, I found that the solution is:

sudo ln -s /usr/lib/python3/dist-packages/gi/_gi.cpython-{36m,37m}-x86_64-linux-gnu.so

This worked for me with Python 3.7 on Ubuntu.

like image 68
pranaychenna Avatar answered Oct 10 '22 16:10

pranaychenna


Ubuntu does not like to switch its default interpreter away from python 3.7.

So switch it back to 3.6 by using

sudo update-alternatives --config python3

After that try to install the gi package:

sudo apt install python3-gi
like image 43
M. Spiller Avatar answered Oct 10 '22 17:10

M. Spiller


This is an old issue, but if someone needs a quick solution , that doesn't imply changing the default Python versions anywhere, just:

sudo python3.6 /usr/bin/apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
like image 9
Souza Avatar answered Oct 10 '22 16:10

Souza


These 2 steps may help you

$ cd /usr/lib/python3/dist-packages/gi
$ sudo ln -s _gi.cpython-{36m,37m}-x86_64-linux-gnu.so
like image 8
Bendy Latortue Avatar answered Oct 10 '22 15:10

Bendy Latortue