Compiling Python 3.8.x Under Linux

Yes, I know. 3.8.x? That’s an older version of Python but there are still a number of current applications and libs that require 3.8 as well as a number of distros that still have 3.8 as the most recent easily installable version. With that being said, the following is a quick how to on getting it compiled under both RedHat/CentOS/Almalinux and Debian based systems.

Install Dependencies

This assumes that you already have the “build-essentials” and kernel headers installed on the box, which is an exercise for the reader.

RedHat/CentOS/Almalinux

yum install -y bzip2-devel expat-devel gdbm-devel ncurses-devel openssl-devel readline-devel wget sqlite-devel tk-devel xz-devel zlib-devel libffi-devel gmp-devel libmpc-devel mpfr-devel openssl-devel

Debian

apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev cur
l libbz2-dev 

Compile Python

The following enables a non-root user to install it into their home directory. You can update the prefix and various paths to suit your needs

# Set the following to the path to the tarball that you downloaded
export PY_TARBALL=/path/to/the/tarbar/Python-3.8.5.tgz

export PY_DIR=$(echo $PY_TARBALL | awk -F/ '{ print $NF }' | sed 's/.tgz//')
export PY_PREFIX=$(echo ~/usr/local/$PY_DIR | tr [:upper:] [:lower:])
mkdir -p ~/usr/local/src ~/usr/local/bin ~/usr/local/include $PY_PREFIX
tar -xzf $PY_TARBALL -C ~/usr/local/src/
cd ~/usr/local/src/$PY_DIR
./configure --prefix=$PY_PREFIX --exec-prefix=$PY_PREFIX
make && make install

Add the following to your PATH in ~/.bash_profile

$PY_PREFIX

Leave a Reply