28

I am a new Ubuntu user running Ubuntu 13.04.

I've been trying to install and use a DeDRM tool, but I've been having problems doing so. I was following some directions that said I needed a version of Python 2.7, but not anything Python 3.0 or later (because 3.0 versions are missing some necessary libraries?). I tried to install Python 2.7.5.6, but it didn't work. I thought it was probably because I had the later version of Python, so I went through terminal and removed Python 3.3, so I could install the earlier version of Python.

Now that I've uninstalled Python 3.3, a lot of applications no longer work, including the terminal and the Ubuntu Software Center. I have no idea how to fix this problem now.

karel
  • 122,292
  • 133
  • 301
  • 332
Frida
  • 281

8 Answers8

28
  1. Open a text-only virtual console by pressing the keyboard shortcut Ctrl + Alt + F3.

  2. At the login: prompt type your username and press Enter.

  3. At the Password: prompt type your user password and press Enter.

  4. Reinstall the default Python 3 version by running the following command:

    sudo apt install python3-all
    
  5. Switch out of the virtual console and return to your desktop environment by pressing the keyboard shortcut Ctrl+Alt+F2.


After you have installed the default Python 3 version, you need to get back your default Ubuntu desktop system. In order to avoid messing something up, do it in the following order:

  1. First install the terminal from a virtual console using the command: sudo apt update && sudo apt install gnome-terminal. If you can't install gnome-terminal at all, skip this step and go to step 2.

  2. Return to your desktop and open the terminal using the keyboard shortcut Ctrl + Alt + T. In Ubuntu 14.04 and earlier from the terminal install the Ubuntu Software Center using the command:

    sudo apt install software-center
    

    In Ubuntu 16.04 and later run this command instead to reinstall the default Software application:

    sudo apt install gnome-software
    

    In Ubuntu 24.04 and later run this command instead to reinstall the default Software application:

    sudo apt install snap-store
    

    If you still can't open the terminal, run the same command from a virtual console instead. If you can't install the default software application at all, skip this step and go to step 3.

  3. Open the terminal and try to open the Ubuntu Software app from the terminal by running the appropriate command. From the Ubuntu Software app install the Ubuntu desktop system or else open the terminal (or a virtual console) and install the Ubuntu desktop system by running the command: sudo apt update && sudo apt install ubuntu-desktop.

karel
  • 122,292
  • 133
  • 301
  • 332
11

This is what I did:

Press Ctrl+Alt+F1 and login.

Run this command:

sudo apt-get remove python/python3

Reboot

Press Ctrl+Alt+F1 and login.

Run these commands:

sudo apt-get install python3
sudo apt-get install python
sudo apt-get install ubuntu-desktop

Reboot

Done!

kiri
  • 28,986
6

To fix the problems with your system you just need to re-install python 3.3.

If you ran for example: sudo apt-get remove python3

You can reverse it by running: sudo apt-get install python3

Of course this is a terminal command and since you said Terminal isn't working this is a problem. You can use TTY1 to log in and run this command by pressing Ctrl+Alt+F1. To return to the normal desktop press Ctrl+Alt+F7.

Paul Tanzini
  • 4,087
3

Here are a few fixes that may help:

  • Manually get the .deb file using apt download and install it using apt install.

  • Manually get 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 get the .deb file using apt download and install it using apt install:

  1. Install the .deb file:
    sudo apt update
    sudo apt download python3 python3-all
    
  2. 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.

  1. 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

  2. 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!)

  1. Make sure you have a backup of everything important.

  2. We are trying this method as a last resort before reinstalling the entire OS.

  3. 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?

  4. 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
wjandrea
  • 14,504
Error404
  • 8,278
  • 3
  • 35
  • 60
2
sudo apt-get install software-center

this will help definitely.

Then from software centre you can install terminal and so on.

kiri
  • 28,986
Raj
  • 145
1

On the same path here.....

I think you can:

  • reboot and enter recovery mode, enable network and enter root terminal
  • check /var/logs/dpkg.log, find out what are the packages you removed. If you removed py3, that would be the last one in the list, after a bunch of lines after a "start remove package" or so. Search with sth like cat /var/logs/dpkg.log | grep -e ".*2021-05-28 15:.*remove .*" (the timestamp is example, but normally you can filter like that, because you don't do apt remove all the time...or you do?)
  • redirect results to a file, for example "list.log", and use awk and tee to create another file
  • tac this file to reverse order(as the earlist removed should be first installed)
  • use awk to pick up the package name after "remove" and pass to apt install to reinstall them

See:

How to reinstall many removed packages at once?

1

This is not tested, but an idea to restore python3 functionality when no valid version of Python 3 is in /usr/bin.

Many other answers here tell the user to use apt, but if no valid version of python3 exists, it can be impossible to use apt.

Instead, you could first try to install the necessary Python 3 packages with dpkg. The below commands apply to Ubuntu 22.04 / AMD64, may be different for other versions and architectures:

First download all packages:

wget \ 
http://mirrors.kernel.org/ubuntu/pool/main/p/python3.10/python3.10_3.10.12-1~22.04.5_amd64.deb \
http://security.ubuntu.com/ubuntu/pool/main/p/python3.10/libpython3.10_3.10.12-1~22.04.5_amd64.deb \
http://mirrors.kernel.org/ubuntu/pool/main/p/python3.10/libpython3.10-stdlib_3.10.12-1~22.04.5_amd64.deb \
http://mirrors.kernel.org/ubuntu/pool/main/p/python3.10/python3.10-minimal_3.10.12-1~22.04.5_amd64.deb \
http://mirrors.kernel.org/ubuntu/pool/main/p/python3.10/libpython3.10-minimal_3.10.12-1~22.04.5_amd64.deb

Then install the downloaded packages with:

sudo dpkg -i \
./python3.10_3.10.12-1~22.04.5_amd64.deb \
./libpython3.10_3.10.12-1~22.04.5_amd64.deb \
./libpython3.10-stdlib_3.10.12-1~22.04.5_amd64.deb \
./python3.10-minimal_3.10.12-1~22.04.5_amd64.deb \
./libpython3.10-minimal_3.10.12-1~22.04.5_amd64.deb

This will hopefully restore basic python3 functionality.

Afterwards, to fix things completely do:

sudo apt install --reinstall --fix-broken python3
Artur Meinild
  • 31,035
0

I have also faced the same problem in Ubuntu 20.04 but after upgrading default python3.8 to python3.10.

I did this to fix the issues: Press Ctrl+Alt+F3 to open the virtual terminal console and login with your username. Check the current python version by typing python3 -V for python3 / python -V for python2. If you have both python versions try step 1.

Step 1: Change the priority of the installed python version by running the following command. It shows the installed python version then give the selection number of the desired version of python3.

sudo update-alternatives --config python3

Close the virtual console by pressing Ctrl+Alt+F2. Check whether problem is solved or move to Step 2.

Step 2: As you mentioned in the question, you have removed python3.3. Install it from the virtual console. Take help from here: How do I install Python 3.3? and close the console. Either it will fix the problem or go through with step 1 to choose the installed python3.3.

Hope it helps!