3.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. This is not a requirement on the OML4Py client.
Python 3.9.5 is required to install and use OML4Py.
These steps describe building and installing Python 3.9.5 for Linux.
- Go to the Python website and
download the Gzipped source tarball. The downloaded file name is
Python-3.9.5.tgzwget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz - Create a directory
$ORACLE_HOME/pythonand extract the contents to this directory:mkdir -p $ORACLE_HOME/python tar -xvzf Python-3.9.5.tgz --strip-components=1 -C $ORACLE_HOME/pythonThe 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-develandncurses-develrpm libraries. Install these packages as sudo or root user:Note:
RPMs must be installed under sudo, or root.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.9.5, enter the following commands, where
PREFIXis the directory in which you installed Python-3.9.5. 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 altinstallNote:
Be sure to use the
--enable-sharedflag if you are going to use Embedded Python Execution; otherwise, using an Embedded Python Execution function results in anextprocerror.Be sure to invoke
make altinstallinstead ofmake installto avoid overwriting the system Python. - Set environment variable
PYTHONHOMEand 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_PATHNote:
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.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 - Create a symbolic link in your
$ORACLE_HOME/python/bindirectory to link to your python3.9 executable, which you can do with the following commands:cd $ORACLE_HOME/python/bin ln -s python3.9 python3
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.9.5 (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.9 executable as described in Step 6.
Parent topic: Install OML4Py for On-Premises Databases