Cannot import name '_gi'

你离开我真会死。 提交于 2020-04-30 06:30:18

问题


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 !


回答1:


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


来源:https://stackoverflow.com/questions/59389831/cannot-import-name-gi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!