Here are a few fixes that may help:
Manually install the .deb file using apt download and install it using apt install.
Manually install the .deb file using wget and install using backend tools like dpkg (which do not depend on Python3) with --force-all argument.
Removing post-installation script to force remove Python and force reinstalling it. (Have a backup before and keep it as the last resort!)
NOTE: To get to a console, you can either boot into recovery mode and open a root shell, or go to a TTY by pressing Ctrl + Alt + F5 .
Manually install the .deb file using apt download and install it using apt install:
- Install the
.deb file:
sudo apt update
sudo apt download python3 python3-all
- Install the
.deb file:
sudo apt install ./python*
Reboot to apply the changes.
Manually get the .deb file using wget and install using backend tools like dpkg (which do not depend on Python3) with --force-all argument.
- Get the
.deb files:
cd ~/Downloads
# For Ubuntu 20.04
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3_3.8.2-0ubuntu2_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3-all_3.8.2-0ubuntu2_amd64.deb
# For Ubuntu 21.10
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3_3.9.7-4_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3-all_3.9.7-4_amd64.deb
- Install the file using
dpkg:
~/Downloads
sudo dpkg -i --force-all ./python*deb
Reboot.
Removing post-installation script to force remove Python and force reinstalling it. (Have a backup before and keep it as the last resort!)
Make sure you have a backup of everything important.
We are trying this method as a last resort before reinstalling the entire OS.
Remove the post-installation and pre-installation files:
cd /var/lib/dpkg/info
ls -alh | grep python | grep -v ".list"
rm python3.pre*
rm python3.post*
rm python.pre*
rm python.post*
We won't remove any signature files or .list files because they are important. For getting more information about the files we have removed see What is a post-installation script for a package?
Reinstall Python3.
cd ~/Downloads
rm -rf python*deb
# For Ubuntu 20.04
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3_3.8.2-0ubuntu2_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3-all_3.8.2-0ubuntu2_amd64.deb
# For Ubuntu 21.10
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3_3.9.7-4_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3-defaults/python3-all_3.9.7-4_amd64.deb
# Install the `.deb` files:
sudo dpkg -i --force-all ./python*deb
Reboot.
After, you have successfully reinstalled Python3, reinstall the application that don't work:
sudo apt update && sudo apt autopurge
sudo apt install --reinstall gnome-terminal ubuntu-desktop gdm3 nautilus
sudo snap remove snap-store
sudo snap install snap-store