【解决方案】ubuntu 解决办法 ImportError: cannot import name ‘_gi‘ from ‘gi‘

请添加图片描述


👉博__主👈:米码收割机
👉技__能👈:C++/Python语言
👉公众号👈:测试开发自动化【获取源码+商业合作】
👉荣__誉👈:阿里云博客专家博主、51CTO技术博主
👉专__注👈:专注主流机器人、人工智能等相关领域的开发、测试技术。


解决办法 ImportError: cannot import name ‘_gi’ from ‘gi’



问题描述

ubuntu上安装使用python3.7解决 ppa 执行 sudo add-apt-repository ppa:ubuntu-toolchain-r/test 报错如下

 mm@mm-desktop:~$  sudo add-apt-repository ppa:ubuntu-toolchain-r/test
 
 ppa:ubuntu-toolchain-r/test Traceback (most recent call last):   File
 "/usr/bin/add-apt-repository", line 12, in <module> 
 from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler   File
 "/usr/lib/python3/mm@mmdist-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
 mm@mm-desktop:~$  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)

解决方案1:

在python3.7的ubuntu系统中使用如下命令:

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

然后再添加 ppa。


解决方案2:

执行如下命令将你的python版本添加到 alternatives ,以我的python3.6/3.7/3.8为例:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1  # 1表示最高优先级
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2  # 2表示次高优先级
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 3  # 3表示最低优先级

执行如下命令将python3版本切换到python 3.6

sudo update-alternatives --config python3

然后再执行命令添加 ppa。


评论 28
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

米码收割机

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值