1. March 2022

Update to Python 3.9 on CentOS Stream 8

By H. Cemre Günay

In today’s guide you’ll learn to install Python 3.9 on CentOS Stream 8 Linux system. Python is general-purpose, interpreted and high-level programming language originally created by Guido van Rossum. Python is created for simplicity, deep integration and great extensibility. You can achieve much more with Python using powerful libraries and tools, including Django, Pygame, Matplotlib, Plotly, e.t.c.

In the next steps we look at the updating of Python 3.9 on CentOS Stream 8. If you’re interested in a full list of features shipped in Python 3.9 check the official release notes.

Python is a cross-platform software package meaning it can run on Linux, Windows, macOS, and BSD systems. As of this article update, the exact latest release of Python 3.9 is version Python 3.6. This is the version of Python that will be installed in this tutorial. So let’s start:

Step 1: Login to your CentOS Stream 8 system as root or user with sudo privileges. You can use remote software like mRemoteNG oder Putty, then update your system.

sudo yum -y install epel-release
sudo yum -y update

Then reboot.

sudo reboot

Install required software development tools required to build Python 3.9 on
CentOS Stream 8:

sudo yum groupinstall "Development Tools" -y
sudo yum install openssl-devel libffi-devel bzip2-devel -y

Confirm gcc is available:

gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Step 2: Download latest Python 3.9 Archive and install wget

sudo yum install wget -y

Use wget to download the latest Python 3.9 release.

wget https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz

Extract the archive file using tar:

tar xvf Python-3.9.10.tgz

Switch to the directory created from the file extraction:

cd Python-3.9*/

Step 3: Install Python 3.9 on CentOS Stream 8 and run the command below to configure Python installation.

./configure --enable-optimizations

Sample output of success:

....
checking for the Linux getrandom() syscall... yes
checking for the getrandom() function... yes
checking for library containing shm_open... -lrt
checking for sys/mman.h... (cached) yes
checking for shm_open... yes
checking for shm_unlink... yes
checking for pkg-config... /usr/bin/pkg-config
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... yes
checking for --with-ssl-default-suites... python
checking for --with-builtin-hashlib-hashes... md5,sha1,sha256,sha512,sha3,blake2
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc

Build Python 3.9 on CentOS Stream 8:

sudo make altinstall

Be patient as this takes quite some time depending on number of CPU cores in your system. If this was successful, you should get a message like below:

....
running install_scripts
copying build/scripts-3.9/pydoc3.9 -> /usr/local/bin
copying build/scripts-3.9/idle3.9 -> /usr/local/bin
copying build/scripts-3.9/2to3-3.9 -> /usr/local/bin
changing mode of /usr/local/bin/pydoc3.9 to 755
changing mode of /usr/local/bin/idle3.9 to 755

Step 4: Run below command to confirm successful installation of Python 3.9 on CentOS Stream 8:

python3.9 --version
Python 3.9.10

Pip3.9 must have been installed as well:

pip3.9 --version
pip 22.0.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

Upgrade pip

 /usr/local/bin/python3.9 -m pip install --upgrade pip
Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.2.4)
Collecting pip
  Downloading pip-22.0.3-py3-none-any.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 1.1 MB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-22.0.3

Example on installing ansible with pip3.9:

pip3.9 install ansible --user
Collecting ansible
  Downloading ansible-5.3.0.tar.gz (38.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.0/38.0 MB 15.2 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Collecting ansible-core~=2.12.2
  Downloading ansible-core-2.12.2.tar.gz (7.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.8/7.8 MB 50.8 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Collecting jinja2
  Using cached Jinja2-3.0.3-py3-none-any.whl (133 kB)
Collecting PyYAML
  Downloading PyYAML-6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (661 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 661.8/661.8 KB 61.7 MB/s eta 0:00:00
Collecting cryptography
  Using cached cryptography-36.0.1-cp36-abi3-manylinux_2_24_x86_64.whl (3.6 MB)
Collecting packaging
  Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting resolvelib<0.6.0,>=0.5.3
  Using cached resolvelib-0.5.4-py2.py3-none-any.whl (12 kB)
Collecting cffi>=1.12
  Downloading cffi-1.15.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (444 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 444.3/444.3 KB 39.1 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
  Using cached pyparsing-3.0.7-py3-none-any.whl (98 kB)
Collecting pycparser
  Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Using legacy 'setup.py install' for ansible, since package 'wheel' is not installed.
Using legacy 'setup.py install' for ansible-core, since package 'wheel' is not installed.
Installing collected packages: resolvelib, PyYAML, pyparsing, pycparser, MarkupSafe, packaging, jinja2, cffi, cryptography, ansible-core, ansible
  Running setup.py install for ansible-core ... done
  Running setup.py install for ansible ... done
Successfully installed MarkupSafe-2.0.1 PyYAML-6.0 ansible-5.3.0 ansible-core-2.12.2 cffi-1.15.0 cryptography-36.0.1 jinja2-3.0.3 packaging-21.3 pycparser-2.21 pyparsing-3.0.7 resolvelib-0.5.4

Well, that’s it! If you have any questions please leave it in the comments below. 🙂