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.6 is required to install and use OML4Py 2.1 client.
These steps describe building and installing Python 3.12.6 for Linux.
- Go to the Python website and
download the Gzipped source tarball. The downloaded file name is
Python-3.12.6.tgz
wget https://www.python.org/ftp/python/3.12.6/Python-3.12.6.tgz
- Create a directory, such as
$HOME/python
, and extract the contents to this directory:mkdir -p $HOME/python tar -xvzf Python-3.12.6.tgz --strip-components=1 -C $HOME/python
The contents of the Gzipped source tarball will be copied directly to
$HOME/python
. - 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
andncurses-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
- To build Python 3.12.6, navigate to
the
$HOME/python
directory where Python-3.12.6 will be installed. Enter the following commands on the Oracle Machine Learning for Python server:cd $HOME/python ./configure --enable-shared --prefix=$HOME/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 anextproc
error.Note:
Be sure to invoke
make altinstall
instead ofmake install
to avoid overwriting the system Python. - Set environment variable
PYTHONHOME
and add it to yourPATH
, and set environment variableLD_LIBRARY_PATH
:export PYTHONHOME=$HOME/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. - Create a symbolic link in your
$HOME/python/bin
directory to link to your python3.12 executable, which you can do with the following commands:cd $HOME/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.6 (main, Aug 14 2024, 15:13:51) [GCC 8.5.0 20210514 (Red Hat
8.5.0-18.0.6)] 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/python/bin
directory to
link to your python3.12
executable as described in Step 7.
Topics:
- Commands Summary for Building and Installing Python for Linux for On-Premises Databases
The commands used to build and install Python for Linux for On-Premises Databases are listed in the following example.
Parent topic: Install OML4Py for On-Premises Databases