Python 2.7 and Python 3.5 are installed on Ubuntu 16.04 by default. In this tutorial we are going to install Python 3.7.

Requirements:

sudo apt update
sudo apt install software-properties-common

Install Python 3.7 package:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7
python3 --version

Configure it as the default interpreter:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 10python3 --version

Install pip

sudo apt install python3-pippip3 --version

If you need to upgrade pip in the future, you can run this:

pip3 install --upgrade pip

You can change the python version by using alternatives:

# python 2
sudo update-alternatives --config python
# python 3
sudo update-alternatives --config python3

--

--