2

I'm currently using WSL2. When I run sudo apt update I get this output and error:

$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:4 https://cli.github.com/packages focal InRelease
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Fetched 324 kB in 1s (386 kB/s)
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

I've tried looking for solutions, however solutions like this but they haven't worked.

Running python3 --version it returns Python 3.9.0+

actuallyatiger
  • 123
  • 2
  • 8

1 Answers1

6

I found this solution, but I had to change the commands slightly.

These are the commands I ran:

$ cd /usr/lib/python3/dist-packages
$ ls -la | grep "apt_pkg.cpython"
$ sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
actuallyatiger
  • 123
  • 2
  • 8