building python 3.9.5 on almalinux 8.3 (purple manul)

Alma Linux (or if you prefer, AlmaLinux) is essentially CentOS with a new coat of paint. IBM, owner of RedHat, who in turn owns CentOS, stirred up a hornet’s nest back in December 2020 when the owners announced that CentOS 8 was changing from a stable release of RHEL 8 to a rolling release of RHEL, and renaming it CentOS Stream. CentOS 8 is being end-of-lifed December of this year, 2021. Needless to say, there are a lot of unhappy CentOS users looking for an alternative.

AlmaLinux ( https://almalinux.org/ ) might be one of those alternatives. Originally created by CloudLinux Inc ( https://www.cloudlinux.com/ ) as a fork of their Linux distribution CloudLinux OS, Alma Linux is “an open-source, community-driven project that intends to fill the gap left by the demise of the CentOS stable release. AlmaLinux OS is a 1:1 binary compatible fork of RHEL® 8 guided and built by the community. As a standalone, completely free OS, AlmaLinux OS enjoys $1M in annual sponsorship from CloudLinux Inc and support from other sponsors. Ongoing development efforts are governed by the members of the community.” To help allay any fears that Alma/Cloud isn’t mature enough, CloudLinux OS “is a RHEL fork that has been in place for over ten years.”

I’ve downloaded the AlmaLinux ISO and created a VM under Parallels Desktop, and so far it behaves just like CentOS, at least for me. What AlmaLinux lacked was an up-to-date version of Python, so I set about building an alternative installation of Python 3.9.5, the current (as of this posting date) Python release.

Setup

Like every other RHEL 8 and its clones, the base OS isn’t set up to successfully build all of Python, including many of its modules. So the first thing you have to do is install all the various support libraries and several applications that Python needs to build.

Let’s start by installing the following list of libraries. These match what I’ve documented in the past for Ubuntu, except that the package names are different for RHEL/AlmaLinux.

sudo dnf install zlib-devel ncurses-devel gdbm-devel nss-devel openssl-devel readline-devel libffi-devel sqlite-devel bzip2-devel

Next install Tk. This will also pick up Tcl, the dependency.

sudo dnf install tk tk-devel

Install these last bits for some obscure libraries.

sudo dnf install lzma xz-devel

Because I’m also working with PyQt6, I need to install the full Qt tool set. This won’t stop Python from building, but after installing Python 3.9.5 and installing PyQt6, any PyQt code you write won’t run. You need this package for the PyQt6 runtime.

sudo dnf install qt qt5-qtbase-devel

Build

Download the Python source and untar it into some area on your system. In the same folder where you untarred the source, create a build directory, such as build-3.9.5, and change directory (cd) into it. Then run the following to configure the build environment.

../Python-3.9.5/configure --enable-optimizations

When finished, run make, then make altinstall where your new Python will be located in /usr/local/bin.

Install and Test

You’ll need to add /usr/local/bin to your path in your .bashrc. Bring up a new shell, or source ~/.bashrc in your current shell, and you should be able to test Python, python3.9 --version.

References

Red Hat resets CentOS Linux and users are angry – https://www.zdnet.com/article/red-hat-resets-centos-linux-and-users-are-angry/

building python 3.9.1 on jetpack 4.5 and the jetson xavier nx

These instructions will help you build Python 3.9.1 on the Jetson Xavier NX Development Kit running JetPack 4.5. There are two broad stages to building this version. The first is the installation of support developer libraries to allow all Python modules to successfully build, especially _ssl. If _ssl fails to build then pip will not be able to negotiate connectivity with any Python repo, making installation of modules fail. After the installation stage come the build steps.

Install Build Prerequisites

To build all Python modules the following libraries need to be installed. Simply copy-and-paste the following line:

sudo apt install zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

Build Python

Download the latest version of Python, build, and install:

  1. Download the latest Python, version 3.9.1, from https://www.python.org/downloads/.
  2. Untar the file (we’ll assume it’s downloaded to the default ~/Downloads):
    tar xvf Downloads/Python-3.9.1.tar.xz
  3. Make a build directory at the same level as the untarred source directory. In my case I named the build directory build-python-3.9.1
  4. Change directory into the build directory.
  5. From within the build directory execute the configure script:
    ../Python-3.9.1/configure --enable-optimizations
  6. Run make with all active cores:
    make -j $(nproc)

    On my machine I enabled all six cores of the Jetson Xavier NX. Running with fewer cores will result in a longer build time.

  7. Install into the alternate location for this version of Python:
    sudo -H make altinstall
  8. Check for the alternate location with which python3.9. It should return /usr/local/bin/python3.9.

I created a Python 3.9.1 virtual work environment, something I highly recommend. I do that to keep the stock and newly installed environments distinct from one another. These are the specific steps I used to create that virtual Python environment.

  1. In your home directory create a work folder. On my system I named it ‘vpython’. Change directory (cd) into it.
  2. Then create a Python VE:
    python3.9 -m venv 39
  3. While you’re there you might as well update pip. Always count on the pip bundled with any version to be out of date with the official version. Using my environment as an example:
    $HOME/vpython/39/bin/python3.9 -m pip install --upgrade pip

Now you’re ready to use the latest Python.

Install PyQt5

I use Python library PyQt5. In order to do that you must install Ubuntu’s Qt5 support libraries as well as the Python module.

  1. Install Ubuntu Qt5 support: sudo apt install qt5-default
  2. Enable Python 3.9 virtual environment: source $HOME/vpython/39/bin/activate
  3. Install Python PyQt5: pip install PyQt5

You’re pretty much free to use Python 3.9 with PyQt5 at this point.

Note that these directions also apply to installation on the Jetson Nano on the same Jetpack version.