Installing IBM Open Enterprise Python 3.10 for z/OS

Petr Plavjaník
5 min readAug 11, 2022

Python has been popular for a long time, and in the last few years, its popularity reached the top level. It is typically used for web application development, automation, data analysis, and machine learning. It can run well on mainframes and z/OS for a few last years and we will see more Python on z/OS in the future.

This story provides instructions on how to install IBM Python to z/OS and how to use it.

IBM started to provide Python for z/OS in 2020, starting with version 3.8.

This story covers the version 3.10.5. If you are looking for the version 3.8, see Installing IBM Open Enterprise Python 3.8 for z/OS.

Installing IBM Python 3.10

The home page of the IBM Python for z/OS is: https://www.ibm.com/products/open-enterprise-python-zos

It comes in two editions:

The PAX edition has some functionality as the SMP/E edition. The only difference is that you can have an optional IBM support for the SMP/E edition.

The PAX edition can be installed by anyone. It is available with no license charge.

Python applications are not IBM z Integrated Information Processor (zIIP)-eligible. Also, overall costs to deploy on z/OS can be reduced as workloads may be eligible to use the New Application Solution pricing model for new production workloads.

We are going to install the PAX edition. To start press the following button on the home page:

Download the only available file HAMB3A0.nonsmpe.pax.Z:

Create zFS Filesystem for Python

You will need about 2GB of space. It is recommended to allocate a new zFS filesystem for it. You can use the following job template and replace ${jobcard} and ${prefix} variables with your job card and the prefix for the data sets with the zFS file system.

JCL that creates a zFS filesystem on z/OS:

${jobcard}
//DEFINE EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DEFINE CLUSTER (NAME(${prefix}.ZFS) -
LINEAR -
TRACKS(40000 40000) -
SHAREOPTIONS(3))
//CREATE EXEC PGM=IOEFSUTL,REGION=0M,COND=(0,LT),
// PARM=('format -aggregate ${prefix}.ZFS')
//SYSPRINT DD SYSOUT=*

You can submit this JCL easily using Zowe CLI. Edit the file in your favorite text editor and replace the variables. Then you can submit it:

# On your computer:
zowe zos-jobs submit local-file create_zfs.jcl

Give Zowe CLI a try! It allows you to interact with z/OS jobs, data sets, z/OS UNIX files and much more from your workstation.

After the job completes, you need to mount the filesystem. Login to your z/OS system via ssh or Putty. Issue following command (you need to replace ${python_dir} and ${prefix} variables):

# In z/OS UNIX System Services:
export PYTHON_DIR=${python_dir}
mkdir $PYTHON_DIR
/usr/sbin/mount -o aggrgrow -f ${prefix}.ZFS $PYTHON_DIR
cd $PYTHON_DIR
mkdir download
# At least 600 MB in /tmp is required. Use the new zFS for it if you are not sure:
mkdir tmp
export TMPDIR=$PYTHON_DIR/tmp

Now, you need to get back to your workstation terminal and copy the package to zFS:

# On your computer:
zowe zos-files upload file-to-uss --binary HAMB3A0.nonsmpe.pax.Z ${python_dir}/download/HAMB3A0.nonsmpe.pax.Z

Let’s go back to z/OS UNIX shell and u npack it:

# On z/OS in $PYTHON_DIR directory
pax -p p -r -f download/HAMB3A0.nonsmpe.pax.Z

The Python is unpackaged to $PYTHON_DIR/usr/lpp/IBM/cyp/v3r10/pyz directory.

Let’s create (e.g. using vi editor) a shell script that will initialize all required environment variables (you need to replace ${python_dir} with your directory):

# Environment variables for PAX archive installation# Configure the PATH and LIBPATH environment variables to include the bin/ directories for IBM Open Enterprise Python for z/OS:
export PYTHON_DIR=${python_dir}
export PYTHONHOME=$PYTHON_DIR/usr/lpp/IBM/cyp/v3r10/pyz
export PATH=$PYTHONHOME/bin:$PATH
export LIBPATH=$PYTHONHOME/lib:$LIBPATH
# Set the auto conversion:
export _BPXK_AUTOCVT='ON'
export _CEE_RUNOPTS='FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)'
# Set the file tagging:
export _TAG_REDIR_ERR=txt
export _TAG_REDIR_IN=txt
export _TAG_REDIR_OUT=txt
# Set the temporary directory (optional):
export TMPDIR=$PYTHON_DIR/tmp

You can activate these variables using:

. ${python_dir}/pyenv.sh

You can add this line to your ~/.profile file to have it activated after login.

You can validate that it is working by:

python3 --version

You should get Python 3.10.5 . Your Python is ready to be used!

Installing Python Packages

This distribution of Python does not come with any additional 3rd party packages. You need to install them using pip3command. For example, use this command to install Flask:

pip3 install flask

If everything works well you will get a similar output:

Collecting flask
Downloading Flask-2.2.2-py3-none-any.whl (101 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 101.5/101.5 kB 909.1 kB/s eta 0:00:00
Collecting itsdangerous>=2.0
Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.0
Downloading click-8.1.3-py3-none-any.whl (96 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 3.3 MB/s eta 0:00:00
Collecting Jinja2>=3.0
Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 1.4 MB/s eta 0:00:00
Collecting Werkzeug>=2.2.2
Downloading Werkzeug-2.2.2-py3-none-any.whl (232 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 232.7/232.7 kB 2.3 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.1.1.tar.gz (18 kB)
Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for MarkupSafe, since package 'wheel' is not installed.
Installing collected packages: MarkupSafe, itsdangerous, click, Werkzeug, Jinja2, flask
Running setup.py install for MarkupSafe ... done
Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.1 Werkzeug-2.2.2 click-8.1.3 flask-2.2.2 itsdangerous-2.1.2

Simple HTTP Server

We will create a very simple HTTP server using the Flask framework.

There is only one file app.py :

from flask import Flask, request
app = Flask(__name__)
@app.route('/greeting')
def hello():
name = request.args.get('name')
return f"Hello, {name}!"

If you have stored the file in EBCDIC, you need to tag it so Python can open it correctly:

chtag -tc IBM-1047 app.py

For more details about codepages and translation in Python on z/OS, see Codesets and Translation.

The web server can be started using one command:

FLASK_APP=app python3 -m flask run --host=0.0.0.0 --port=11055

This is how it works:

Top: Request via the HTTPie client, Bottom: Flask on z/OS

Summary

Python has finally an IBM supported version for z/OS. It comes in both PAX and SMP/E distributions.

You have seen how to install it, set up the environment, and create a very simple HTTP server.

You can learn more about IBM Python from its documentation.

If you are interested in how to mainframe work with Python, see following stories:

--

--

Petr Plavjaník

Petr’s main areas of expertise are mainframes and automation, and using modern development tools and languages such as Java, Python, and Node.js on z/OS.