无法导入名称“ _gi”
问题内容:
我正在尝试使用add-apt-repository
命令将存储库添加到ppa,但是_gi
找不到来自Python的模块。
我做了这个命令: sudo add-apt-repository ppa:s-mankowski/ppa-kf5
这是回溯:
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)
我在使用Python3.7的Ubuntu上,我尝试了许多解决方案,例如,但它不起作用:
$ 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
我不能使用该sudo add-apt-repository ppa:s-mankowski/ppa- kf5
命令,但是可以正常运行Python文件python3 {file}
。
谢谢您的帮助 !
问题答案:
Ubuntu不喜欢将其默认解释器从python 3.7切换开。
所以通过使用将其切换回3.6
sudo update-alternatives --config python3
之后,尝试安装gi
软件包:
sudo apt install python3-gi