Dev Notes

Software Development Resources by David Egan.

Build Python from Source in Linux


Linux, Python
David Egan

Get the latest version of Python on Ubuntu

Download the latest version of Python from here: https://www.python.org/downloads/

# Download Python:
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz

# Download the detached signature file:
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz.asc

Verify Download

Checksums (MD5) are presented on the dowloads/releases/python-xxx/ page.

Check the md5sum manually by running:

md5sum Python-3.8.2.tgz

You can also automate the check by building a suitable manifest file and checking this:

# Get md5 checksum from website, filename corresponds to the download
cat > manifest
f9f3768f757e34b342dbc06b41cbc844  Python-3.8.2.tgz

# Ctrl-d to exit cat
md5sum -c checksum 2>&1 | grep OK 
# Output if correct:
Python-3.8.2.tgz: OK

The website also posts the filesize, so you should also check this.

Import Relevant GPG Key From Trusted Server

# Imports key sourced here: https://www.python.org/downloads/
gpg --keyserver keyserver.ubuntu.com --recv-keys B26995E310250568

Check that the downloaded file has been signed by this key:

# Reference the signature file
gpg --verify Python-3.8.2.tgz.asc
# Correct output:
gpg: assuming signed data in `Python-3.8.2.tgz'
gpg: Signature made Tue 25 Feb 2020 10:41:46 GMT using RSA key ID 10250568
gpg: Good signature from "Łukasz Langa (GPG langa.pl) <lukasz@langa.pl>"
gpg:                 aka "Łukasz Langa <lukasz@python.org>"
gpg:                 aka "Łukasz Langa (Work e-mail account) <ambv@fb.com>"
gpg:                 aka "[jpeg image of size 24479]"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: E3FF 2839 C048 B25C 084D  EBE9 B269 95E3 1025 0568

Extract

tar -xvf Python-3.8.2.tgz

This unpacks files into a directory (in this case, Python-3.8.2) which you should move into:

cd Python-3.8.2

Check out the README.rst.

Build

./configure --enable-optimizations
make
make test
sudo make install

This will install Python as python3.


comments powered by Disqus