A.2 Troubleshooting

A.2.1 OML4Py

A.2.1.1 Error when importing matplotlib

Issue: Error occurs when running this command to import matplotlib in a notebook:
%python

import matplotlib.pyplot as plt
plt.style.use('seaborn')
plt.figure(figsize=[10,5]) 

oml.graphics.boxplot(IRIS[:, :4], notch=True,
                     showmeans = True,
                     labels=IRIS.columns[:4])
                     
plt.title('Distribution of IRIS Attributes')

plt.ylabel('cm')
Error message:
Fail to execute line 2: plt.style.use('seaborn')

Traceback (most recent call last):

  File "/usr/local/lib/python3.12/site-packages/matplotlib/style/core.py", line 137, in use

    style = _rc_params_in_file(style)

            ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.12/site-packages/matplotlib/__init__.py", line 866, in _rc_params_in_file

    with _open_file_or_url(fname) as fd:

  File "/usr/local/lib/python3.12/contextlib.py", line 137, in __enter__

    return next(self.gen)

           ^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.12/site-packages/matplotlib/__init__.py", line 843, in _open_file_or_url

    with open(fname, encoding='utf-8') as f:

         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

FileNotFoundError: [Errno 2] No such file or directory: 'seaborn'....

....

OSError: 'seaborn' is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in `style.available`)
Resolution: This error occurred due to a change that was introduced in Matplotlib 3.7.0. It affects all Python 3.12.x versions. Specifically, using plt.style.use('seaborn') was deprecated in Matplotlib 3.6 and removed in 3.7. You will encounter this error if you're using Python 3.12.x (any point version).

Note:

Ensure that you import Matplotlib ≥ 3.7.0.

A.2.1.2 Error when importing Python interpreters

Issue: The error “Fail to open Python Interpreter” encountered in OML notebooks.

Resolution: This issue is related to version conflict. To avoid version conflicts, do not install packages that are already included in OML4Py. This issue is related to version conflict. For a complete list of pre-installed packages and their versions, to view the list of Python interpreters, run the following:
%python 
import os os.listdir('/usr/local/lib/python3.12/site-packages')

A.2.1.3 How to add HostAce using cursor in Python?

To add HostAce using cursor in Python, run the following command in a Python paragraph:

%python 
cursor.execute("BEGIN pyqAppendHostAce('USER_OML', '<adb_instance>.oraclecloudapps.com');

A.2.1.4 Error when installing OML4Py Server for On-Premises Oracle AI Database

Issue: Encountered the following error when installing OML4Py Server for On-Premises Oracle AI Database

SQL> SELECT * FROM sys.pyq_config;  NAME          VALUE
      _____________ _____________________________________________________  PYTHONHOME
      /opt/oracle/product/26ai/dbhomeFree/python             PYTHONPATH
      /opt/oracle/product/26ai/dbhomeFree/oml4py/modules     VERSION       2.0
      PLATFORM      ODB                                                    DSWLIST
      oml.*;pandas.*;numpy.*;matplotlib.*;sklearn.*           SQL> begin   2
      sys.pyqScriptCreate('pyqFun1', 'func = lambda: "Hello World from a lambda!"', FALSE, TRUE);
      3  end;   4  /  PL/SQL procedure successfully completed.  SQL> SELECT name, value FROM
      table(pyqEval(NULL,'XML','pyqFun1')); SELECT name, value FROM
      table(pyqEval(NULL,'XML','pyqFun1')) * ERROR at line 1: ORA-20000: PyQuery error ImportError:
      Error importing numpy: you should not try to import numpy from its source directory; please
      exit the numpy source tree, and relaunch your python interpreter from there. ORA-06512: at
      "PYQSYS.PYQ$EVALIMPL_IN", line 77 ORA-06512: at "PYQSYS.PYQ$EVALIMPL_IN", line 74
      ORA-06512: at "SYS.DBMS_SQL", line 1838 ORA-06512: at "PYQSYS.PYQ$ETSTART", line 176
      ORA-06512: at "PYQSYS.PYQEVALIMPL", line 54 ORA-06512: at line 1
Resolution: This error usually occurs if you are running Python from inside the Numpy directory. To resolve this issue, ensure that the working directory in your SQL API session is not pointing to a local numpy/ folder.
  1. Do cd .. to exit the numpy directory.
  2. Now, follow the steps to install OML4Py Server for On-Premises Oracle AI Database again.

A.2.2 OML4R

A.2.2.1 How to add rows to a table in the database through an ore.frame

To modify the database table:
  1. Use the Oracle R package.
  2. Then run an INSERT into command to add the rows to the table.

A.2.2.2 Unable able to push an object to Autonomous AI Lakehouse from an Oracle Machine Learning Notebook session using OML4R equivalent of OML4Py

Issue: Used this command to push an object to Autonomous AI Lakehouse.

The Oracle Machine Learning for Python command that works:

oml_iris = oml.create(iris_df, table = 'IRIS_OML4PY')

Error

Error in .oci.GetQuery(conn, statement, data = data, prefetch = prefetch, : ORA-06598: insufficient INHERIT PRIVILEGES privilege ORA-06512: at "RQSYS.RQ$ADDRSESSIONREFDBOBJECT", line 1 ORA-06512: at line 1 Traceback: 1. ore.push(iris_df, table = "IRIS_OML4R") 2. ore.push(iris_df, table = "IRIS_OML4R") 3. .ore.addObjects(env, tabName, "table", "purge") 4. .ore.QueryEnv$addRefObjects(objName, objType, objParm) 5. .ore.dbGetQuery(stmt, data = refdbobjs) 6. .ore.QueryEnv$dbGetQuery(qry, noframe = noframe, return = return, . ...) 7. ROracle::dbGetQuery(.ore.con(), qry, ...) 8. ROracle::dbGetQuery(.ore.con(), qry, ...) 9. .local(conn, statement, ...) 10. .oci.GetQuery(conn, statement, data = data, prefetch = prefetch, . bulk_read = bulk_read, bulk_write = bulk_write)

Resolution: Run this command instead:

oml.create != ore.push 

Note:

Oracle Machine Learning for Python has its own push function. Moreover, the push function does not take a table argument.

A.2.3 OML Notebooks

A.2.3.1 How to install third-party packages for both Python and R in Oracle Machine Learning Notebooks

How to install third-party packages for both Python and R in Oracle Machine Learning Notebooks

Oracle Machine Learning Notebooks in Autonomous AI Lakehouse leverages Conda environment to install third-party packages in Oracle Machine Learning on Oracle Autonomous AI Database Serverless. The ADMIN user creates (installing any needed packages) and uploads the Conda environment to Object Storage. Once uploaded to Object Storage, these environments are available to all non-ADMIN users, who can load them directly into their Oracle Machine Learning Notebooks sessions. These conda environments work with Python and R, whether you are using OML4R (R, SQL, REST APIs) or OML4Py (Python, SQL, REST APIs).

For more information, see Install third-party packages

A.2.3.2 How to upload data from a .csv file into a Pandas DataFrame

How to upload data from a .csv file into a Pandas DataFrame

For example, how can I upload data from a .csv file into a Pandas DataFrame?

Resolution: To import the data from this IRIS.csv file present in Object Storage, and read into a Pandas DataFrame, run the following command:
%python

import pandas as pd
import ssl

url="https://objectstorage.us-ashburn-1.oraclecloud.com/n/adwc4pm/b/OML_Data/o/IRIS.csv"

ssl._create_default_https_context = ssl._create_unverified_context
test = pd.read_csv(url)
test.head()
To fetch the same information for R, use read.csv() instead. Run the following command:
%r

url="https://objectstorage.us-ashburn-1.oraclecloud.com/n/adwc4pm/b/OML_Data/o/IRIS.csv"

test = read.csv(url)
head(test)

A.2.3.3 "Allow Run" button to warn users about potential security threat

Issue: In Example template notebooks, if there is any javascript in the notebook codes or results, an Allow Run button will be displayed to warn users about potential threat for security reasons. If you don’t want the warning to be displayed, then avoid using javascript in the (example) notebook.

Resolution: For example:

Replace <a href="https://github.com/oracle/oracle-db-examples/tree/master/machine-learning" onclick="return ! window.open('https://github.com/oracle/oracle-db-examples/tree/master/machine-learning');">Oracle Machine Learning GitHub folder</a>

with

<a href="https://github.com/oracle/oracle-db-examples/tree/master/machine-learning" target="_blank">Oracle Machine Learning GitHub folder</a>

This also has the same behavior without javascript.

A.2.3.4 Resource Management in Oracle Machine Learning

Issue: Does Oracle Machine Learning impose any limitations on traffic or resource usage originating from a single source when triggering embedded Python execution, particularly for heavy workloads or resource-intensive tasks?

Resolution: For each embedded REST execution call, the Autonomous AI Database broker provisions an individual container from the VM based on the service levels - Low, Medium, High and releases it after completion. The resource allocated for the container is limited and the Autonomous AI Database load balancer controls the network traffic.

A.2.4 Conda

A.2.4.1 Error when loading libraries in Conda environments in Oracle Machine Learning Notebooks

Issue: When loading Conda libraries with statsmodels library and its dependencies, the following error occurs.

Error message:
Traceback (most recent call last): File "/tmp/python4753125085416874695/zeppelin_python.py", line 145, in <module> import oml, numpy, pandas, scipy, matplotlib, oracledb, sklearn File "/usr/local/lib/python3.12/site-packages/oml/__init__.py", line 43, in <module> from oml.core import * File "/usr/local/lib/python3.12/site-packages/oml/core/__init__.py", line 33, in <module> from .methods import connect File "oml/core/methods.py", line 79, in init oml.core.methods.....
Resolution:
  1. Adjust the version of statsmodels that is being installed.
  2. Use the conda search command to view the library version and the Python build. This includes the Python version.
  3. Use statsmodels==0.14.0 to address this issue.