Ubuntu 18.04 中 sudo apt update 出现问题:如果 /usr/bin/test -w /var/lib/command-not-found/,则调用后成功

Ubuntu 18.04 中 sudo apt update 出现问题:如果 /usr/bin/test -w /var/lib/command-not-found/,则调用后成功

当我使用 更新软件时,终端给出了这些错误sudo apt update

Hit:1 http://it.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://it.archive.ubuntu.com/ubuntu bionic-updates InRelease                                                                                       
Hit:3 http://it.archive.ubuntu.com/ubuntu bionic-backports InRelease                                                                                     
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease                                     
Hit:5 http://archive.canonical.com/ubuntu bionic InRelease                
Traceback (most recent call last):                    
  File "/usr/lib/cnf-update-db", line 8, in <module>
    from CommandNotFound.db.creator import DbCreator
ModuleNotFoundError: No module named 'CommandNotFound'
Reading packages list... 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  

这些是sudo apt install --reinstall command-not-found

Reading package lists... Done 
Building dependency tree        
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/5.188 B of archives
After this operation, 0 B of additional disk space will be used.
(Reading the database ... 225797 files and directories currently installed.)
Preparations for extracting ... / command-not-found_18.04.4_all.deb ...
Extracting command-not-found (18.04.4) on (18.04.4) ...
Configuring command-not-found (18.04.4) ...
libdvd-pkg: Package libdvdcss2-1.4.2-1 was removed, stop processing...

当我重新安装 command-not-found 后再次尝试该命令时sudo apt update,结果与第一个文本块中描述的相同。

答案1

在所有当前支持的 Ubuntu 版本中打开终端并输入:

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

如果这不起作用,简单的重启有时可以解决这个问题。

答案2

这解决了我相同/类似的问题:

cd /usr/lib/python3/dist-packages
ls -la /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

来源:Linux 问题

答案3

软件包 libdvdcss2-1.4.2-1 已被删除,停止处理...

也困扰着我的系统...并且对于新手来说,上述方法的更完整的解释 - 有效 - 哇哦!...这就是我所做的!

代码当然是在终端内部使用的......

sudo find / -name 'CommandNotFound'

导致出现这种情况,显示这条模糊的路径

[sudo] ack 的密码:find:'/run/user/1000/gvfs':权限被拒绝

/usr/lib/python3/dist-packages/CommandNotFound

因此,这里引用的上述方法中不明显的部分......

sudo cp -r /path/of/CommandNotFound /usr/lib/

导致错误,显然因为它是“通用的”

但是这个修改后的版本在第一个命令中找到了这个文件路径,解决了这个问题......“/usr/lib/python3/dist-packages/CommandNotFound”

$ sudo cp -r /usr/lib/python3/dist-packages/CommandNotFound /usr/lib/

问题就解决了

我希望这能有所帮助,马克

答案4

我遇到了类似的问题,并通过以下方式修复:

sudo find / -name 'CommandNotFound'
sudo cp -r /path/of/CommandNotFound /usr/lib/

相关内容