How to Install OML4Py Server and OML4Py Client for your Oracle Databases?

·

6 min read

In this article, I will guide you how to Install OML4Py Server and OML4Py Client.

1. Prerequisites:

Required OS level packages/libraries for OML4Py:

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

To check whether these libraries are already exist or not, you can run the following commands as “root” user or run it as ‘sudo-enabled’ OS user like “opc” in Oracle OCI Cloud.

$ 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

Please be noted that it won’t show any output if the library is not exist.

Now, simply run the “yum install” command for all the above libraries. If the library is already exist, it will upgrade it to the latest version. If the library is not exist, it will install it freshly to the latest version. So, basically, install all the above libraries by running the following commands as “root” user or sudo-enabled OS user.

$ yum install perl-Env
$ yum install libffi-devel
$ yum install openssl
$ yum install openssl-devel
$ yum install tk-devel
$ yum install xz-devel
$ yum install zlib-devel
$ yum install bzip2-devel
$ yum install readline-devel
$ yum install libuuid-devel
$ yum install ncurses-devel

Note that, in the above screenshot, I have passed all the package names in one single command itself. This syntax is also correct only which will install all the above packages together.

Once you execute the above command; it will ask you for the confirmation. Type ‘y’ to confirm.

Once the command is finished executing, you will see the output similar to the below one:

OML4Py Configuration Requirements

Oracle Machine Learning for Python VersionPython VersionOn-Premises Oracle Database Release
2.03.12.019c, 21c, 23ai

Required Python Version

To install the Python 3.12*, please read my other article here

Required Supporting Packages

Both the OML4Py Server and OML4Py Client installations for an Oracle Database require that you also install a set of supporting Python packages, as described below:

pandas==2.1.1
setuptools==68.0.0
scipy==1.12.0
matplotlib==3.8.4
oracledb==2.2.0
scikit-learn==1.4.2
numpy==1.26.4
onnxruntime==1.17.0
onnxruntime-extensions==0.10.1
onnx==1.16.0
torch==2.2.0+cpu
transformers==4.38.1
sentencepiece==0.2.0
joblib==1.3.2

--extra-index-url download.pytorch.org/whl/cpu

Out of above all packages, the following packages/libraries are required to install only for OML4Py Client.

onnxruntime
onnxruntime-extensions
onnx

transformers
sentencepiece

These libraries support the ONNX conversion feature on the OML4Py client and so it should be installed only on the client side only.

Similarly, the joblib library is required to install only for the OML4Py Server and so it should be installed only on the server side only.

All other packages are required to be installed on both OML4Py Client and OML4Py Server.

Note: oracledb 2.2.0 or later version is required to invoke vector database SQL APIs in 23ai.

2. Installing required packages on OML4Py Client Machine:

In the OML4Py Client Machine where the Oracle Instant Client is installed, install the following libraries:

If the Oracle Instant Client is not done previously, you can refer to the corresponding section in this article where the steps for installing the Oracle Instant Client is also given.

Now, let’s first verify whether the pip3.12/pip3 and python3.12/python3 is pointing to right Python location.

Now, create a file called “oml4py_client_packages.txt” and include all the below packages/libraries and save it.

$ vi oml4py_client_packages.txt
--extra-index-url download.pytorch.org/whl/cpu
pandas==2.1.1
setuptools==68.0.0
scipy==1.12.0
matplotlib==3.8.4
oracledb==2.2.0
scikit-learn==1.4.2
numpy==1.26.4
onnxruntime==1.17.0
onnxruntime-extensions==0.10.1
onnx==1.16.0
torch==2.2.0
transformers==4.38.1
sentencepiece==0.2.0

Now, execute the following command that will install all the above-mentioned packages for the OML4Py Client.

$ pip3.12 install -r packages.txt

If the above command is successful, you will see the output similar to the one as shown below:

3. Verifying the Packages Installation for OML4Py Client:

Invoke the Python prompt and import the below libraries. If all the libraries are getting imported successfully without throwing any errors, then it means that the installation is successful.

import pandas
import scipy
import matplotlib
import oracledb
import sklearn
import numpy
import onnx
import torch
import onnxruntime_extensions
import transformers
import sentencepiece

4. Installing required packages on OML4Py Server Machine:

In the OML4Py Server Machine where the Oracle Database is installed, all the below mentioned packages must be installed into $ORACLE_HOME/oml4py/modules so that they can be detected by the Embedded Python Execution process.

Run the following commands:
$ id
$ which pip3.12
$ which python3
$ which python3.12
$ . oraenv (Set the DB)
$ ls -l $ORACLE_HOME/oml4py/modules

Now, create a file called “oml4py_server_packages.txt” and include all the below packages/libraries and save it.

$ vi oml4py_server_packages.txt
pandas==2.1.1
setuptools==68.0.0
scipy==1.12.0
matplotlib==3.8.4
oracledb==2.2.0
joblib==1.3.2
scikit-learn==1.4.2
numpy==1.26.4

$ cat oml4py_server_packages.txt

Now, execute the following command that will install all the above-mentioned packages for the OML4Py Server.

$ pip3.12 install -r oml4py_server_packages.txt --target=$ORACLE_HOME/oml4py/modules

If the above command is successful, you will see the output similar to the one as shown below:

5. Verifying the Packages Installation for OML4Py Server:

Invoke the python prompt and import the below libraries. If all the libraries are getting imported successfully without throwing any errors, then it means that the installation is successful.

import numpy
import pandas
import scipy
import matplotlib
import oracledb
import sklearn

6. Installing OML4Py Server for Oracle Database 23ai:

To install the OML4Py Server, run the installation SQL script pyqcfg.sql located in “$ORACLE_HOME/oml4py/server

The OML4Py server needs to be installed on CDB$ROOT first, followed by installation on the desired PDB.

Once the OML4Py Server is installed successfully in CDB$ROOT, install it in the PDB level.

7. Verifying the OML4Py Server Installation:

Create a DB user and test the OML:

You can also test the connectivity via oml library in Python as follows:

$ python3
\>>> import oml
\>>> oml.connect(user='oml_user', password='********', host='
localhost', port=1521, service_name='orcl23ai_pdb1.**********.vcndmmumbai.oraclevcn.com')
\>>> oml.script.create("TEST", func='def func():return 1 + 1', overwrite=True)
\>>> res = oml.do_eval(func='TEST')
\>>> res
\>>> oml.script.drop("TEST")
\>>> quit()

8. Installing Oracle Instant Client:

The OML4Py Client requires Oracle Instant Client to connect to an Oracle database. Suppose, if you have already installed Oracle Instant Client, then skip this part. Similarly, suppose, if Oracle Database is also running on the same machine, then you don’t need to install Oracle Instant Client.

To install Oracle Instant Client, download the Software by running the following commands:

$ mkdir -p /u02/oracle_23ai_instant_client
$ cd /u02/oracle_23ai_instant_client
$ wget
download.oracle.com/otn_software/linux/inst..

Now, unzip the file.

$ unzip instantclient-basic-linux.x64-23.4.0.24.05.zip

Unzipping the file will create a new directory called “instantclient_23_4” which will contain the Oracle Instant Client Files.

Now, install the libaio / libaio1 package with sudo privileged user or as the root user:

$ sudo yum install libaio

In .bash_profile, export the LD_LIBRARY_PATH variable with the Oracle Instant Client location

export LD_LIBRARY_PATH=/u02/oracle_23ai_instant_client/instantclient_23_4:$LD_LIBRARY_PATH

9. Installing OML4Py Client:

Download the OML4Py Client Installation Zip file from OTN website.

Once it is downloaded (OML4Py 2.0.1), copy it to your Server and unzip it.

$ unzip OML4Py_Client_Installation_File.zip

It will create a directory called “client” and then extracts the below 4 files into this directory.

OML4PInstallShared.pm
oml-2.0-cp312-cp312-linux_x86_64.whl
client.pl
oml4py.ver

Now, from the same directory where you unzipped the above file, execute the following command.

$ rpm -qa perl-Env
$ perl -Iclient client/client.pl --help

Now, execute the following command which will install the OML4Py Client.

$ perl -Iclient client/client.pl --no-deps

10. Verifying the OML4Py Client Installation:

To verify the OML4Py Client Installation, invoke the Python prompt and import the oml library. If the oml library is getting imported successfully without any errors, then it means that the OML4Py Client Installation is done successfully.

$ python3
\>>> import oml
\>>> oml.__version__
\>>> oml.__path__

Thanks for reading this long article. Hope, it helped you to progress your work.