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

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

For 23ai, building Python is only necessary for the client. The database has Python 3.12.1 in $ORACLE_HOME/python.

Note:

The feature supporting text transformers from Hugging Face by converting them into ONNX format models will only work on the OML4Py client. It is not supported on the OML4Py server.

Python 3.12.0 or Python 3.12.1 is required to install and use OML4Py.

These steps describe building and installing Python 3.12.0 for Linux.

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

    The contents of the Gzipped source tarball will be copied directly to /home/user/python

  3. Go to the new directory:
    cd /home/user/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.

    Install these 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.12.0, enter the following commands, where /home/user/python is the directory in which you installed Python-3.12.0. The command on the Oracle Machine Learning for Python server will be:
    cd /home/user/python
    ./configure --enable-shared --prefix=/home/user/python
    
    make clean; make
    make altinstall

    Note:

    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.

    Note:

    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=/home/user/python
    export PATH=$PYTHONHOME/bin:$PATH
    export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH

    Note:

    In order to use Python for OML4Py, the variables must be set, and these variables must appear before system Python in PATH and LD_LIBRARY_PATH.
  7. Create a symbolic link in your /home/user/python/bin directory to link to your python3.12 executable, which you can do with the following commands:
    cd /home/user/python/bin
    ln -s python3.12 python3

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

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.12.0 (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)
/home/user/python/bin/python3

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 /home/user/python/bin directory to link to your python3.12 executable as described in Step 6.