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.

3
  • I you press Ctrl+Alt+F1 do you still get a terminal? Press Ctrl+Alt+F7 to get back to the desktop. Nov 30, 2013 at 3:28
  • It's really called a VC (Virtual Console). Please follow one of the answers given here. A standard installation of Ubuntu will give you the last (stable) release of both Python2 and Python3 --- they are fundamental to have Ubuntu running, so you really need them. Notice that you could need to reinstall more software, like software ... I will advise to reinstall at least ubuntu-desktop.
    – Rmano
    Nov 30, 2013 at 3:57
  • is your problem fixed??
    – Sukupa91
    Nov 30, 2013 at 4:53

7 Answers 7

26
  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
    

    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, either software-center or gnome-software. 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.

13
  • 1
    That will reinstall python, but not automatically all the software that is gone with it. Maybe reinstalling ubuntu-desktop will reinstall back most of the thing needed to have a working system back.
    – Rmano
    Nov 30, 2013 at 4:00
  • I'm waiting to see how this thing plays out. I'd start off with the gnome-terminal and software-center packages if they're not still there. Your suggestion for installing ubuntu-desktop makes a lot of sense to me, but I'm still worried about the possibility of messing up the default desktop icons and also the IBus input method user interface. This can be a painfully difficult problem to repair, and so I don't want to tell Frida to reinstall ubuntu-desktop except as a last resort. Ping me from chat Ask Ubuntu General Room any time you want to talk more about this or the Python 2/Python 3 thing.
    – karel
    Nov 30, 2013 at 4:14
  • 1
    edit as of April 18 of 2019-- 18.04 and later now needs you to press Ctrl + Alt + F1 to return to Ubuntu Desktop. also, yes; you do in fact need to reinstall ubuntu-desktop still so that it can "rebuild" everything; but everything will still be running and perfectly fine when you're done. i uh, learned this all the hard way of course.
    – xTerrene
    Apr 18, 2019 at 7:57
  • @EarthToAccess I noticed this console update today when I updated my software using the Software Updater, but my Ubuntu 18.04 still uses Ctrl+Alt+F7 to return to the desktop. I'll try it again after I reboot and see if Ctrl+Alt+F1 also works because of the update.
    – karel
    Apr 18, 2019 at 8:05
  • 1
    If you tried everything and it didn't work please ask a new question.
    – karel
    Jun 23, 2022 at 13:15
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!

1
  • Thank you! The winning part here for me was sudo apt-get install ubuntu-desktop. Apr 8, 2021 at 12:07
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.

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
1
  • First option did a trick for me. But I also did sudo apt-get install ubuntu-desktop after installing pyhton
    – Sharpey
    May 1, 2023 at 23:12
2
sudo apt-get install software-center

this will help definitely.

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

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?

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!

You must log in to answer this question.

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