Unable to set default python version to python3 in ubuntu

后端 未结 19 1575
遥遥无期
遥遥无期 2020-11-28 01:38

I was trying to set default python version to python3 in Ubuntu 16.04. By default it is python2 (2.7). I followed below steps :

相关标签:
19条回答
  • 2020-11-28 02:00

    At first, Make sure Python3 is installed on your computer

    Go to your terminal and type:

    cd ~/ to go to your home directory

    If you didn't set up your .bash_profile yet, type touch .bash_profile to create your .bash_profile.

    Or, type open -e .bash_profile to edit the file.

    Copy and save alias python=python3 in the .bash_profile.

    Close and reopen your Terminal. Then type the following command to check if Python3 is your default version now:

    python --version

    You should see python 3.x.y is your default version.

    Cheers!

    0 讨论(0)
  • 2020-11-28 02:01

    To change to python3, you can use the following command in terminal alias python=python3.

    0 讨论(0)
  • 2020-11-28 02:02

    At First Install python3 and pip3

    sudo apt-get install python3 python3-pip
    

    then in your terminal run

    alias python=python3
    

    Check the version of python in your machine.

    python --version
    
    0 讨论(0)
  • 2020-11-28 02:03

    As it says, update-alternatives --install needs <link> <name> <path> and <priority> arguments.

    You have link (/usr/bin/python), name (python), and path (/usr/bin/python3), you're missing priority.

    update-alternatives --help says:

    <priority> is an integer; options with higher numbers have higher priority in automatic mode.

    So just put a 100 or something at the end

    0 讨论(0)
  • 2020-11-28 02:03

    Do

    cd ~
    gedit .bash_aliases
    

    then write either

    alias python=python3
    

    or

    alias python='/usr/bin/python3'
    

    Save the file, close the terminal and open it again.
    You should be fine now! Link

    0 讨论(0)
  • 2020-11-28 02:05

    To change Python 3.6.8 as the default in Ubuntu 18.04 to Python 3.7.

    Install Python 3.7

    Steps to install Python3.7 and configure it as the default interpreter.

    1. Install the python3.7 package using apt-get

      sudo apt-get install python3.7

    2. Add Python3.6 & Python 3.7 to update-alternatives

    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
    
    1. Update Python 3 to point to Python 3.7

      sudo update-alternatives --config python3 Enter 2 for Python 3.7

    2. Test the version of python

    python3 --version
    Python 3.7.1 
    
    0 讨论(0)
提交回复
热议问题