问题描述
我正在尝试使用 add-apt-repository
命令向 ppa 添加存储库,但未找到 Python 中的 _gi
模块.
I'm trying to add a repository to ppa with the add-apt-repository
commands but the _gi
module from Python is not found.
我做了这个命令: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,我尝试了很多解决方案,但它不起作用:
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
我无法使用 sudo add-apt-repository ppa:s-mankowski/ppa-kf5
命令,但使用 python3 {file}
运行 Python 文件有效.
I can't use the sudo add-apt-repository ppa:s-mankowski/ppa-kf5
command but running a Python file with python3 {file}
works.
感谢您的帮助!
推荐答案
Ubuntu 不喜欢从 python 3.7 切换其默认解释器.
Ubuntu does not like to switch its default interpreter away from python 3.7.
因此使用
sudo update-alternatives --config python3
然后尝试安装 gi
包:
sudo apt install python3-gi
这篇关于无法导入名称“_gi"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!