Ubuntu18.04 apt update报错解决分享

报错

Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
 

sam@ubuntu:~$ sudo apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                            
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                      
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease                                         
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease                                       
Hit:5 https://download.sublimetext.com apt/stable/ InRelease                    
Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 8, in <module>
    from CommandNotFound.db.creator import DbCreator
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code

解决方法(from: https://itectec.com/ubuntu/ubuntu-problem-with-sudo-apt-update-in-ubuntu-18-04-post-invoke-success-if-usr-bin-test-w-var-lib-command-not-found/):

apt download python3-minimal
sudo apt install --reinstall ./python3-minimal_*.deb
sudo apt install -f

Execution:

sam@ubuntu:~$ apt download python3-minimal
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-minimal amd64 3.6.7-1~18.04 [23.7 kB]
Fetched 23.7 kB in 1s (16.8 kB/s)          
sam@ubuntu:~$ sudo apt install --reinstall ./python3-minimal_*.deb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'python3-minimal' instead of './python3-minimal_3.6.7-1~18.04_amd64.deb'
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 28 not upgraded.
Need to get 23.7 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-minimal amd64 3.6.7-1~18.04 [23.7 kB]
Fetched 23.7 kB in 1s (17.0 kB/s)          
(Reading database ... 180143 files and directories currently installed.)
Preparing to unpack .../python3-minimal_3.6.7-1~18.04_amd64.deb ...
Unpacking python3-minimal (3.6.7-1~18.04) over (3.6.7-1~18.04) ...
Setting up python3-minimal (3.6.7-1~18.04) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
sam@ubuntu:~$ sudo apt install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
sam@ubuntu:~$ sudo apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                            
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                      
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease                                         
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease                                       
Hit:5 https://download.sublimetext.com apt/stable/ InRelease                    
Reading package lists... Done

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值