Upgrade python 3.5 to 3.7 in Ubuntu
I have a requirement in our new enhancement project which only works with python 3.7 or +. The current version in using is 3.5. I have followed the below steps to upgrade from 3.5 to 3.7.
Step 1: Check the current version
$ python3 --version
My output is : Python 3.5.2
Step 2: Update Ubuntu packages
sudo apt-get update
Step 3: Install python3.7
$ sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev
$ sudo apt-get install python3-pip python3.7-dev
$ sudo apt-get install python3.7
If you come across “Unable to locate package python3.7-dev” error which means you don’t have the repository.
Hence you need to install below packages:
$ sudo apt-get install -y software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
Run python3.7 install command:
$ sudo apt-get install python3-pip python3.7-dev
$ sudo apt-get install python3.7
Step 4: Update python 3 to point to python 3.7
Now python 3.7 is installed but when you type python3 it will still point to python 3.5. Hence we need to execute it as python 3.7.
Add python 3.5 & 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
Type this command to configure:
sudo update-alternatives --config python3
Selection Path Priority Status
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
* 0 /usr/bin/python3.5 2 auto mode
1 /usr/bin/python3.7 1 manual mode
Select “1” to make python 3.7 at auto mode.
Check the version: “python3 — version” and you will see the result as “Python 3.7.9”