10

After I installed Python 3.5 and ran the commands below, my terminal and many other programs won't launch any more.

cd /usr/bin
sudo rm python3
sudo ln -s python3.5 python3 

How can I restore the default Python version again to fix these problems?

Byte Commander
  • 107,489
Behzad Ghotbifar
  • 123
  • 2
  • 2
  • 7

4 Answers4

18

Step 1: Opening a terminal

You said that you could not open a terminal any more. That is because the standard terminal emulator in Ubuntu is gnome-terminal, which can't run without a working python3, as that's one of its dependencies:

$ apt-cache depends gnome-terminal | grep python
 Depends: python3
 Depends: python3-gi

However, there are alternatives:

  1. Use another terminal emulator:

    You can simply use another terminal emulator than gnome-terminal, for example xterm which should also be installed by default. Search it in the dash's application lens (Super+A) or just run xterm from the HUD (Alt+F2).

    A new terminal window will open from where you can undo your previous operations. It's (in my opinion) less comfortable than the default gnome-terminal, but surely does its job without depending on any Python components:

    $  LANG=C apt-cache depends xterm | grep python
    $  
    
  2. Use a TTY terminal:

    Instead of using a terminal emulator (terminal window in a graphical environment) you can also temporarily switch to a real terminal (console only, no graphics) by pressing Ctrl+Alt+F1 (or any F [n] key with n in the range of 1 to 6).

    You switch back to the graphical surface (usually TTY7) with Ctrl+Alt+F7 (or another F [n] key with n in the range of 7 to 12, depending on your user sessions).

    In the TTY, you will have to log in by typing your username and password again first. Then it works like a normal terminal. Don't forget to log out of the TTY session again with Ctrl+D or the command exit when you're done.


Step 2: Restoring the original python3

Whatever method you used to get a terminal, the following reparation step is the same.

You have to restore the original /usr/bin/python3 file, which was actually a symlink to python3.4 (or absolute path /usr/bin/python3.4). This is done by the following simple command:

sudo ln -sf /usr/bin/python3.4 /usr/bin/python3
Byte Commander
  • 107,489
  • You can download Visual Studio Code and use it's built-in terminal - I had this same problem and I fixed it using the Visual Studio Code terminal via running the various commands through that terminal to fix the Python stuff https://code.visualstudio.com/#alt-downloads – Kyle Bridenstine Mar 25 '20 at 19:19
  • It should be noted that the graphical session is typically on TTY1 and 2 for newer versions of Ubuntu, instead of TTY7. – mchid Aug 03 '21 at 14:25
9

You can't replace Python 3.4 with 3.5 on Ubuntu, because many (system) applications rely on it. This includes the symlink python3.

Given that you have not removed python3.4, restore the original symlink with

 cd /usr/bin
 sudo rm python3
 sudo ln -s python3.4 python3

Call Python3.5 directly with python3.5

Nephente
  • 5,595
  • 1
  • 17
  • 23
  • You can download Visual Studio Code and use it's built-in terminal - I had this same problem and I fixed it using the Visual Studio Code terminal via running the various commands through that terminal to fix the Python stuff https://code.visualstudio.com/#alt-downloads – Kyle Bridenstine Mar 25 '20 at 19:20
2

I had the same issue, and the following worked for me:

sudo update-alternatives --config python3

Selecting 1 genreated:

* 1            /usr/bin/python3.5   1         manual mode
Eliah Kagan
  • 117,780
  • You can download Visual Studio Code and use it's built-in terminal - I had this same problem and I fixed it using the Visual Studio Code terminal via running the various commands through that terminal to fix the Python stuff https://code.visualstudio.com/#alt-downloads – Kyle Bridenstine Mar 25 '20 at 19:20
0

Terminals and other applications cannot be launched because the latest version of python3 on your ubuntu does not symlink to python3. You can overcome this by doing a symlink in the following way:

Check the version of python3 in /usr/bin:

ls /usr/bin | grep python

Selecting the latest version of the python3(python3.5) symlink becomes python3:

sudo update-alternatives --config python3

Choose your version of python3 (python3.5) with number. if successful, the result is

update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python3 (python3) in manual mode

Open your default terminal or restart


if there is an error in point 3, such as:

update-alternatives: warning: forcing reinstallation of alternatives /usr/bin/python3.7 because the python3 link group is broken

Please repeat point 3 and choose another version of python3.