4.2 Build and Install Python for Linux for On-Premises Databases
Instructions for installing Python for Linux for an on-premises oracle database.
The Python installation on the database server must be executed by the Oracle user and not sudo, root, or any other user. However, this is not a requirement for the OML4Py client.
Python 3.12.0 is required to install and use OML4Py.
Build and Install Python on Oracle Linux 7
These steps describe building and installing Python 3.12.0 on Oracle Linux 7.
- Python 3.12 requires
OpenSSL 3.0.12
, which needs to be installed from source on Linux 7. Download the OpenSSSL source tarball.wget https://www.openssl.org/source/old/3.0/openssl-3.0.12.tar.gz
- Install the Perl modules
perl-IPC-Cmd
andperl-Digest-SHA
if unavailable.- Run the following commands to check if the modules
are already installed on your
system:
If the commands return output likerpm -qa perl-IPC-Cmd rpm -qa perl-Digest-SHA
perl-IPC-Cmd-1.02-1.el7.noarch
orperl-Digest-SHA-6.02-1.el7.x86_64
, it means the modules are installed. - If no value is returned, the modules are not
available on the system and need to be installed as sudo or
root. Run the following command to install
them::
sudo yum install perl-IPC-Cmd perl-Digest-SHA
- Run the following commands to check if the modules
are already installed on your
system:
- Extract the
OpenSSL
archive. Create a subdirectory nameddist
insideopenssl
directory. Go to theopenssl
directory.tar -xvzf openssl-3.0.12.tar.gz cd openssl-3.0.12 mkdir dist export OPENSSL_HOME=<full-path-to-openssl-3.0.12>
- Run the following command to configure and
make.
./configure enable-fips --prefix=$OPENSSL_HOME/dist/openssl --openssldir=$OPENSSL_HOME/dist/ssl make clean; make make install
- Check if the OpenSSL libraries have been successfully
compiled and the openssl folder containing them has been
created.
ls dist/openssl/lib64
engines-3/ libcrypto.so libssl.a libssl.so.3 pkgconfig/ libcrypto.a libcrypto.so.3 libssl.so ossl-modules/
ls dist/ssl
certs/ ct_log_list.cnf.dist misc/ openssl.cnf.dist ct_log_list.cnf fipsmodule.cnf openssl.cnf private/
- Install the Perl modules
- Download the Python 3.12.0 source
tarball.
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
- Before continuing, check if there’s already a Python
installation.
- Look for a folder named python in this location:
$ORACLE_HOME
. - If there’s no python folder found, proceed to step 2.2.
- If a folder is found, rename the existing folder to
avoid conflicts with the new installation. For example:
mv $ORACLE_HOME/python $ORACLE_HOME/python-old
- Look for a folder named python in this location:
- Create a directory
$ORACLE_HOME/python
and extract the contents of the tarball to this directory:
The contents of the Gzipped source tarball will be copied and extracted directly tomkdir -p $ORACLE_HOME/python tar -xvzf Python-3.12.0.tgz --strip-components=1 -C $ORACLE_HOME/python
$ORACLE_HOME/python
. - Create
PYTHONHOME
environment variable and change the directory to:export PYTHONHOME=$ORACLE_HOME/python cd $PYTHONHOME
- Copy the
openssl
libraries to python folder.mkdir $PYTHON_HOME/include $PYTHONHOME/ssl cp -r $OPENSSL_HOME/dist/openssl/lib64/* $PYTHONHOME/lib cp -r $OPENSSL_HOME/dist/ssl/* $PYTHONHOME/ssl cp -r $OPENSSL_HOME/include/openssl $PYTHONHOME/include
- Go to the new
directory:
cd $ORACLE_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
- Compile and install
Python.
./configure --enable-shared OPT='-fwrapv -O3 -Wall' --prefix=$PYTHONHOME --with-openssl=$PYTHONHOME --with-openssl-rpath=$PYTHONHOME/lib make clean; make make altinstall
-
Create a symbolic link in the
$PYTHONHOME/bin
directory to the python3.12 executableln -s $PYTHONHOME/bin/python3.12 $PYTHONHOME/bin/python3
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.Be sure to invoke
make altinstall
instead ofmake install
to avoid overwriting the system Python. - Make Python libraries available and add Python3.12 bin
folder to the
path.
export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH export PATH=$PYTHONHOME/bin:$PATH
- Verify that Python was compiled
correctly.
python3
Python 3.12.0 (main, Apr 5 2024, 18:58:17) [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 ssl
ssl.OPENSSL_VERSION 'OpenSSL 3.0.12 24 Oct 2023'
- Before continuing, check if there’s already a Python
installation.
Build and Install Python on Oracle Linux 8
These steps describe building and installing Python 3.12.0 on Linux 8.
- Download the Python 3.12.0 source
tarball.
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
- Create a directory
$ORACLE_HOME/python
and extract the contents to this directory:mkdir -p $ORACLE_HOME/python tar -xvzf Python-3.12.0.tgz --strip-components=1 -C $ORACLE_HOME/python
The contents of the Gzipped source tarball will be copied directly to
$ORACLE_HOME/python
- Go to the new
directory:
cd $ORACLE_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.0, enter the
following commands, where
PREFIX
is the directory in which you installed Python-3.12.0. 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
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.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=$ORACLE_HOME/python export PATH=$PYTHONHOME/bin:$PATH export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH
Note:
To use Python for OML4Py, the variables must be set, and these variables must appear before the system Python in PATH and LD_LIBRARY_PATH. - Create a symbolic link in your
$ORACLE_HOME/python/bin
directory to link to your python3.12 executable, which you can do with the following commands:cd $ORACLE_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
For both Oracle Linux 7 and Oracle Linux 8
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)
/u01/app/oracle/product/19.3/dbhome_1/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 PREFIX/bin
directory to link to your python3.12
executable as described in
Step 6.
- Command 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