Can't Change the default python 3.5 to 3.7 in ubuntu 16.04

8,914

After install Python 3.6.x and/or 3.7.x you need to make python3 use the new installed python instead of the default 3.5 release.

Run following commands to add the alternatives:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 3

Then you can switch between the python versions for python3:

sudo update-alternatives --config python3

BUG: There is a bug for this method: gnome-terminal won’t launch after switch to newer version.

To solve this, you need to recreate the symlink:

sudo rm /usr/bin/python3

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

Check version with:

python3 -V
Share:
8,914

Related videos on Youtube

subham basu roy chowdhury
Author by

subham basu roy chowdhury

Updated on September 18, 2022

Comments

  • subham basu roy chowdhury
    subham basu roy chowdhury over 1 year

    I am running ubuntu 16.04. Recently I have installed python3.7.3 by running these commands:

    sudo apt update
    
    
    
    sudo apt install software-properties-common
    
    
    
    sudo add-apt-repository ppa:deadsnakes/ppa
    
    sudo apt update 
    sudo apt install python3.7
    

    after running these commands I typed:

    python3.7
    

    it says:

    Python 3.7.3 (default, Mar 26 2019, 01:59:45) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information.

    But the default python in ubuntu still is python3.5. To configure it I am ran the following command in the terminal:

    sudo update-alternatives --config python
    

    the output of the command is as follows:

    There is only one alternative in link group python (providing /usr/bin/python): /usr/bin/python3.5 Nothing to configure.

    Any help to resolve this issue is highly appreciated.

    Thanks in advance.

    • domih
      domih about 3 years
      It seems generally a bad idea to change the Python where the system depends on, as I experienced it. In short, gnome-terminal did not start any more, and I could not solve it for my Ubuntu 18.04. See [stackoverflow.com/questions/56218562/… thread) for details. I ended up reverting the changes to the alternatives, and used Python3.8 for the application only.
  • Marcelo
    Marcelo over 4 years
    To avoid the error, you can use an alias: alias python3='/usr/bin/pytho3.6' Then re-login and check version: python --version