3

I have a VM running Ubuntu 20.04 inside windows and I tried to fix a problem, and now I get the error

ModuleNotFoundError: No module named 'apt-pkg'

I did run the code

sudo apt install python3-apt

which did not help. When restarting the VM I get the same error (i.e. I cannot actually open a Terminal on the GUI probably because of that error). I need to change to a non-GUI terminal...

I followed to solution suggested HERE but the command

ls -l | grep apt_pkg

did not return anything.

I also tried the answer in this question and I got errors like follows after running the first command sudo apt remove python3-apt:

enter image description here

Alex
  • 801

2 Answers2

1

Solution: Run the following command and choose python3.8:

sudo update-alternatives --config python3
Alex
  • 801
1

Lots of built-in/system scripts use the following "shebang" to indicate what binary should run the script. This is expected to be a link to the system-default version of Python:

#!/usr/bin/python3

On Ubuntu 20.04 this is expected to be python3.8 and many scripts assuming that this is the version used when calling python3. If you have installed a different version of python then these scripts may fail unexpectedly. You need to ensure that /usr/bin/python3 points at python3.8.


One way to do this is to follow the alternative answer to this question offered by @Alex which I elaborate on here. Assuming you have installed update-alternatives AND added different versions of Python AND configured one of those to be the default, then this should allow you to choose a different version of python:

sudo update-alternatives --config python3

To keep things fixed, you can set python3.8 to be the default version by (re)adding it to update-alternatives with a suitably high priority (I use 100 in the example below).

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 100

Re-running the tool with the --config python3 parameters again should list the alternatives and their priority.