3.2 Build and Install Python for Linux for On-Premises Databases

Instructions for installing Python for Linux for an on-premises Oracle database.

Python 3.9.5 required to install and use OML4Py.

These steps describe building and installing Python 3.9.5 for Linux.

  1. Go to the Python website and download the Gzipped source tarball. The downloaded file name is Python-3.9.5.tgz
    wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
  2. Create a directory $ORACLE_HOME/python and extract the contents to this directory:
    mkdir -p $ORACLE_HOME/python
    tar -xvzf Python-3.9.5.tgz --strip-components=1 -C $ORACLE_HOME/python

    The contents of the Gzipped source tarball will be copied directly to $ORACLE_HOME/python

  3. Go to the new directory:
    cd $ORACLE_HOME/python
  4. OML4Py requires the presence of the perl-Env, libffi-devel, openssl, openssl-devel, tk-devel, xz-devel, zlib-devel, bzip2-devel, readline-devel, libuuid-devel and ncurses-devel libraries.

    You can confirm that those libraries are present by issuing the following commands:

    rpm -qa perl-Env
    rpm -qa libffi-devel
    rpm -qa openssl 
    rpm -qa openssl-devel
    rpm -qa tk-devel
    rpm -qa xz-devel
    rpm -qa zlib-devel
    rpm -qa bzip2-devel
    rpm -qa readline-devel
    rpm -qa libuuid-devel
    rpm -qa ncurses-devel

    If the libraries are present, then those commands should return messages such as the following. Depending on the version of Linux that you are using, such as version 7.3 or 7.5, the exact messages differ slightly.


    The actual value returned depends on the version of Linux that you are using.

    If no output is returned, then install the packages as sudo or root user.

    sudo yum install perl-Env libffi-devel openssl openssl-devel tk-devel xz-devel zlib-devel bzip2-devel readline-devel libuuid-devel ncurses-devel
  5. To build Python 3.9.5, enter the following commands, where PREFIX is the directory in which you installed Python-3.9.5. The command on the Oracle Machine Learning for Python server will be:
    cd $ORACLE_HOME/python
    ./configure --enable-shared --prefix=$ORACLE_HOME/python
    make clean; make
    make altinstall


    Be sure to use the --enable-shared flag if you are going to use Embedded Python Execution; otherwise, using an Embedded Python Execution function results in an extproc error.

    Be sure to invoke make altinstall instead of make install to avoid overwriting the system Python.

  6. Set environment variable PYTHONHOME and add it to your PATH, and set environment variable LD_LIBRARY_PATH:
    export PYTHONHOME=$ORACLE_HOME/python
    export PATH=$PYTHONHOME/bin:$PATH

    pip will return warnings during package installation if the latest version is not installed. You can upgrade the version of pip to avoid these warnings:

    python3 -m pip install --upgrade pip
  7. Create a symbolic link in your $ORACLE_HOME/python/bin directory to link to your python3.9 executable, which you can do with the following commands:
    cd $ORACLE_HOME/python/bin
    ln -s python3.9 python3

You can now start Python by running the command python3. To verify the directory where Python is installed, use the sys.executable command from the sys package. For example:

$ python3
Python 3.9.5 (default, Feb 22 2022, 15:13:36)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44.0.3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)

This returns the absolute path of the Python executable binary.

If you run the command python3 and you get the error command not found, then that means the system cannot find an executable named python3 in $PYTHONHOME/bin. A symlink is required for the OML4Py server installation components. So, in that case, you need to create a symbolic link in your PREFIX/bin directory to link to your python3.9 executable as described in Step 6.