Building Python 3.x
Below versions of Python are available in respective distributions at the time of creation of these build instructions:
- RHEL (7.8, 7.9) have
3.6.8
- RHEL (8.6, 8.8, 8.9, 9.0, 9.2, 9.3) have
3.11.5
- SLES 12 SP5 has
3.6.15
- SLES 15 SP5 has
3.11.5
- Ubuntu 20.04 has
3.9.5
- Ubuntu 22.04 has
3.10.6
- Ubuntu 23.10 has
3.11.4
The instructions provided below specify the steps to build Python version 3.12.2 on Linux on IBM Z for following distributions:
- RHEL (7.8, 7.9, 8.6, 8.8, 8.9, 9.0, 9.2, 9.3)
- SLES (12 SP5, 15 SP5)
- Ubuntu (20.04, 22.04, 23.10)
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.
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.2/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.
export SOURCE_ROOT=/<source_root>/
-
RHEL (7.8, 7.9)
sudo yum install -y bzip2-devel gdbm-devel libdb-devel libffi-devel libuuid-devel make ncurses-devel readline-devel sqlite-devel tar tk-devel wget xz xz-devel zlib-devel sudo yum install -y devtoolset-11-gcc-c++ source /opt/rh/devtoolset-11/enable
-
RHEL (8.6, 8.8, 8.9, 9.0, 9.2, 9.3)
sudo yum install -y bzip2-devel gcc gcc-c++ gdbm-devel libdb-devel libffi-devel libnsl2-devel libuuid-devel make ncurses ncurses-devel openssl openssl-devel readline-devel sqlite-devel tar tk-devel wget xz zlib-devel glibc-langpack-en diffutils xz-devel
-
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 readline-devel sqlite3-devel tar tk-devel wget xz-devel zlib-devel gzip
-
SLES 15 SP5
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 readline-devel sqlite3-devel tar tk-devel wget xz-devel zlib-devel gzip timezone
-
Ubuntu (20.04, 22.04, 23.10)
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
- Build and install OpenSSL from source (SLES 12 SP5 and RHEL 7.x 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"
cd $SOURCE_ROOT
wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz
tar -xzf Python-3.12.2.tgz
Skipping the prefix will result in installing Python in default location /usr/local
.
cd $SOURCE_ROOT/Python-3.12.2
./configure --prefix=<build-location>
For instance,
cd $SOURCE_ROOT/Python-3.12.2
./configure --prefix=/usr/local
cd $SOURCE_ROOT/Python-3.12.2
make
sudo make install
sudo cp -f /etc/python3start /etc/pythonstart #Only on SLES 12 SP5 if file `/etc/pythonstart` does not exist
python3 -V
The output should be:
Python 3.12.2
cd $SOURCE_ROOT/Python-3.12.2
Run the test suites
make test
cd $SOURCE_ROOT/Python-3.12.2
make test TESTOPTS="-v test_<suite_name>"
For instance,
cd $SOURCE_ROOT/Python-3.12.2
make test TESTOPTS="-v test_pdb"
Note: Following python test cases have been observed to fail intermittently. They should pass on rerun.
test_cppext
test_tools
The information provided in this article is accurate at the time of writing, but on-going development in the open-source projects involved may make the information incorrect or obsolete. Please open issue or contact us on IBM Z Community if you have any questions or feedback.