-
Install packages needed
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
-
Download desire release's source code from here:
curl -O https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
-
Extract
tar -xf Python-3.7.3.tar.xz
-
Nevigate to the python source directory and run the
configurescript that will perform a number of checks to make sure all the dependencies on your system are present:cd Python-3.7.3./configure --enable-optimizations
Note:
--enable-optimizationsoption will optimize the Python binary by running multiple tests which will make the build preocess slower. -
Run
maketo start the build process:make -j 8
Note: For faster build time, modify the
-jflag according to your processor. To figure otu the numbef for the cores, you can find it withnproccommand. The code snippet above is for machines with 8 cores. -
After the build is done, install the Python binaries by running the following:
sudo make altinstall
Note: Avoid using
make installas it'll overwrite the default systempython3binary. -
To verify that the Python has been installed successfully, run:
python3.7 --version
-
Update python3.7 to update alternatives:
sudo update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3.7 1
-
Update
python3to point to python3.7:sudo update-alternatives --config python3
Original sources:
[1] https://linuxize.com/post/how-to-install-python-3-7-on-debian-9/