3.2 Build and Install Python for Linux for On-Premises Databases
Instructions for installing Python for Linux for an on-premises Oracle database.
Python 3.9.5 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.tgz
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
- Create a directory
$ORACLE_HOME/python
and extract the contents to this directory:mkdir -p $ORACLE_HOME/python tar -xvzf Python-3.9.5.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.You can confirm that those libraries are present by issuing the following commands:
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
If the libraries are present, then those commands should return messages such as the following. Depending on the version of Linux that you are using, such as version 7.3 or 7.5, the exact messages differ slightly.
perl-Env-1.04-2.el7.noarch libffi-devel-3.0.13-19.el7.i686 libffi-devel-3.0.13-19.el7.x86_64 openssl-devel-1.0.2k-19.0.1.el7.x86_64 tk-devel-8.5.13-6.el7.i686 xz-devel-5.2.2-1.el7.x86_64 zlib-devel-1.2.7-17.el7.x86_64 zlib-devel-1.2.7-17.el7.i686 bzip2-devel-1.0.6-13.el7.x86_64 bzip2-devel-1.0.6-13.el7.i686 readline-devel-6.2-11.el7.i686 readline-devel-6.2-11.el7.x86_64 libuuid-devel-2.23.2-61.el7_7.1.x86_64 ncurses-devel-5.9-14.20130511.el7_4.x86_64
The actual value returned depends on the version of Linux that you are using.
If no output is returned, then install the 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.9.5, enter the following commands, where
PREFIX
is 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 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
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/bin
directory 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.