10

The terminal gave me these errors when updating the software with 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  

These are the results of 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...

When I tried the command sudo apt update again after reinstalling command-not-found, the results were the same as described in the first text block.

1

6 Answers 6

13

In all currently supported versions of Ubuntu open the terminal and type:

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

If that doesn't work a simple reboot will sometimes solve this problem.

2
  • Thanks. It works for me. Dec 14, 2021 at 19:49
  • Thank you. You saved me.
    – Green Y.
    Oct 17, 2023 at 15:36
2

This solved my same/similar issue:

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

Source: Linux Question

0
1

Package libdvdcss2-1.4.2-1 was removed, stop processing...

was plaguing my system too ... and for a newbie fuller explanation of the above method - THAT WORKED - WOOHOO! ... here is what I did!

Codes are used inside of terminal of course ...

sudo find / -name 'CommandNotFound'

resulted in this, showing this obscure path

[sudo] password for ack: find: ‘/run/user/1000/gvfs’: Permission denied

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

So the unobvious part of the above method quoted here ...

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

resulted in an error, obviously as it is "Generic" so to speak

but this altered version with this file path found in the first command solved the problem ... "/usr/lib/python3/dist-packages/CommandNotFound"

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

and the problem is gone

I hope this helps, Mark

1

apt is using several third party tools, among them command-not-found. This is meant to react to unknown commands and suggest which packages you'd need to install to get those commands. But the command-not-found package had not been maintained for several years, which led to multiple problems.

To sort out one specific problem, in late 2021 some helpful people built new versions of the command-not-found package for several Ubuntu versions. So, if you're using either Focal / 20.04, Hirsute / 21.04, or Impish / 21.10, you want to make sure that you have the latest version of command-not-found for your respective distribution.

For other distributions, you may consider disabling Acquire::GzipIndexes in apt's configuration (because those compressed indexes tripped command-not-found up this time around). Or you may consider uninstalling the command-not-found package, if you don't need it for other purposes. But I haven't looked into any possible side effects of removing the package.

0

I got a similar problem, and fixed it by this way:

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

It's not ideal, but this is my current workaround:

sudo apt purge command-not-found 
sudo apt --purge autoremove
sudo bash -c 'apt update && apt full-upgrade && apt autoremove && apt clean'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .