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 :
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!
To change to python3, you can use the following command in terminal alias python=python3
.
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
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
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
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.
Install the python3.7 package using apt-get
sudo apt-get install python3.7
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
Update Python 3 to point to Python 3.7
sudo update-alternatives --config python3
Enter 2 for Python 3.7
Test the version of python
python3 --version
Python 3.7.1