python - 无法导入名称 '_gi'

标签 python ubuntu pi

我正在尝试使用 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命令,但使用 python3 {file} 运行 Python 文件作品。

谢谢您的帮助 !

最佳答案

感谢 a comment by Wilhelm ,我发现解决方法是:

sudo ln -s /usr/lib/python3/dist-packages/gi/_gi.cpython-{36m,37m}-x86_64-linux-gnu.so
这对我在 Ubuntu 上使用 Python 3.7 有效。

关于python - 无法导入名称 '_gi',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59389831/

相关文章:

python - 如何防止数据在 matplotlib 散点图中拥挤在一起?

python - 根据值列表在 python 中重新排序字典

python - 在Python中轻松实现检测置信区间内的二维码

r - 为什么布冯的针法估算 pi 不能产生预期值?

python - MFRC522 RFID Python3 脚本无法启动 : No such file or directory

python - 无论操作系统如何,Python zipfile 是否始终使用 posixpath 文件名?

linux - 由于docker无法在ubuntu 18.04上更新和升级

postgresql - 使用 Postgres 数据库时调用了哪些函数

python - Ubuntu OpenCV:加载视频文件时程序崩溃

python - pi计算中的段错误(python)