Building Python 3.x - linux-on-ibm-z/docs GitHub Wiki

Building Python 3.12.x

Below versions of Python are available in respective distributions at the time of creation of these build instructions:

  • RHEL (8.8, 8.10) have 3.12.3
  • RHEL (9.2, 9.4) have 3.12.1
  • SLES 12 SP5 has 3.6.15
  • SLES 15 SP5 has 3.12.3
  • SLES 15 SP6 has 3.12.4
  • Ubuntu 20.04 has 3.9.5
  • Ubuntu 22.04 has 3.11.0
  • Ubuntu 24.04 has 3.12.3

The instructions provided below specify the steps to build Python version 3.12.6 on Linux on IBM Z for following distributions:

  • RHEL (8.8, 8.10, 9.2, 9.4)
  • SLES (12 SP5, 15 SP5, 15 SP6)
  • Ubuntu (20.04, 22.04, 24.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

1: Build and Install Python 3.12.x

1.1. Build using script

If you want to build Python using manual steps, go to STEP 1.2.

Use the following commands to build Python using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Python3/3.12.6/build_python3.sh

# Build Python
bash build_python3.sh  [Provide -t option for executing build with tests] 

If the build completes successfully, go to STEP 1.7. In case of error, check logs for more details or go to STEP 1.2 to follow manual build steps.

1.2. Install dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (8.8, 8.10, 9.2, 9.4)

    sudo yum install -y bzip2-devel gcc gcc-c++ gdbm-devel libdb-devel libffi-devel libuuid-devel make ncurses-devel openssl-devel tar tk-devel wget xz zlib-devel diffutils xz-devel patch
  • SLES 12 SP5

    sudo zypper install -y gawk gcc gcc-c++ gdbm-devel libbz2-devel libdb-4_8-devel libffi48-devel libuuid-devel make ncurses-devel tar tk-devel wget xz-devel zlib-devel gzip 
  • SLES (15 SP5, 15 SP6)

    sudo zypper install -y gawk gcc gcc-c++ gdbm-devel libbz2-devel libdb-4_8-devel libffi-devel libnsl-devel libopenssl-devel libuuid-devel make ncurses-devel tar tk-devel wget xz-devel zlib-devel gzip 
  • Ubuntu (20.04, 22.04, 24.04)

    sudo apt-get update
    sudo apt-get install -y gcc g++ libbz2-dev libdb-dev libffi-dev libgdbm-dev liblzma-dev libncurses-dev libreadline-dev libsqlite3-dev libssl-dev make tar tk-dev uuid-dev wget xz-utils zlib1g-dev patch

1.3. Build additional dependencies

  • Build and install OpenSSL from source (SLES 12 SP5 only)
      cd $SOURCE_ROOT
      wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz --no-check-certificate
      tar -xzf openssl-1.1.1w.tar.gz
      cd openssl-1.1.1w
      ./config --prefix=/usr/local --openssldir=/usr/local
      make
      sudo make install
      sudo ldconfig /usr/local/lib64
      export PATH=/usr/local/bin:$PATH
    
      export LDFLAGS="-L/usr/local/lib/ -L/usr/local/lib64/"
      export LD_LIBRARY_PATH="/usr/local/lib/:/usr/local/lib64/"
      export CPPFLAGS="-I/usr/local/include/ -I/usr/local/include/openssl"
    
    

1.4. Download source code

cd $SOURCE_ROOT
wget https://www.python.org/ftp/python/3.12.6/Python-3.12.6.tgz
tar -xzf Python-3.12.6.tgz

1.5. Configure the build

Skipping the prefix will result in installing Python in default location /usr/local.

cd $SOURCE_ROOT/Python-3.12.6
./configure --prefix=<build-location>

For instance,

cd $SOURCE_ROOT/Python-3.12.6
./configure --prefix=/usr/local

1.6. Build the source and install the binaries

cd $SOURCE_ROOT/Python-3.12.6
make
sudo make install

sudo cp -f /etc/python3start /etc/pythonstart  #Only on SLES 12 SP5 if file `/etc/pythonstart` does not exist

1.7. Verify Python3 version

python3 -V

The output should be:

Python 3.12.6

2: Testing (Optional)

2.1. Run the functional verification test suites

cd $SOURCE_ROOT/Python-3.12.6

Run the test suites

make test

2.2. Make verbose test suite

cd $SOURCE_ROOT/Python-3.12.6
make test TESTOPTS="-v test_<suite_name>"

For instance,

cd $SOURCE_ROOT/Python-3.12.6
make test TESTOPTS="-v test_pty"

Note: Following python test case has been observed to fail intermittently. It should pass on rerun.

  • test_pty

References:

⚠️ **GitHub.com Fallback** ⚠️