How to Install Python 3.12 version in an Oracle Database Server or in any Unix Server?

·

4 min read

In this article, I will guide you how to install the latest Python Version (3.12.3) in your Oracle Database Server that may be running in your On-Premise Environment, or Compute VM environment in Oracle OCI or DBCS environment in Oracle OCI or running in any other Cloud Vendor. Please be noted that the same steps can be used to install on a plain Unix Server as well.

1. Install the required OS Level Libraries/Packages

You first need to install the required OS level libraries/packages which are shown below:

perl-Env
libffi-devel
openssl
openssl-devel
tk-devel
xz-devel
zlib-devel
bzip2-devel
readline-devel
libuuid-devel
ncurses-devel libraries

To install the above libraries/packages, simply execute the “yum install” command as root user or ‘sudo-privileged’ 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

Once you execute the above command; it will ask you for the confirmation. Type ‘y’ to confirm.

Once the command is finished executing, you will see the output similar to the below one:

2. Download the Python Zipfile

Now, open the official Python Website (www.python.org) and download the latest Python version according to your OS platform and copy it to your Server. Or else, simply use the “wget” command which will directly download the Python Installation zipfile in your server itself. Here, I am logged in as “oracle” user and then downloading the latest Python version using the “wget” command as shown below.

$ wget python.org/ftp/python/3.12.3/Python-3.12.3...

As you see above, the current python version is “3.6.8” in my environment. We will be installing the latest version such as “3.12.3”. The “wget” command will download the latest Python Software zip file. Once that is done, unzip the downloaded file and start installing the latest python version.

Before that, I am going to create a new directory called “python312” and then I will be using/configuring this new directory as my new PYTHON HOME location so that the existing old Python Installation will not get impacted.

$ mkdir python312
$ mv Python-3.12.3.tgz ./python312
$ cd ./python312
$ pwd
$ ls -ltr

Now, unzip the file inside the newly created directory by running the following command. This will extract all the files from the Python zipfile and keep it in the same location.

$ tar -xvzf Python-3.12.3.tgz --strip-components=1

3. Build the Python

Now, we have to build the Python. So, from the extracted folder location (PYTHON HOME), run the “configure” command as shown below:

$ cd /home/oracle/python312
$ ./configure --prefix=/home/oracle/python312 --enable-shared

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 an extproc error.

Once, the above “configure” command is completed, run the following “make” command.

$ make clean; make

If the above command is successful, you will see the output similar to the one as shown below:

After that, run the below “make” command.

$ make altinstall

Note: Be sure to invoke make altinstall instead of make install to avoid overwriting the system Python.

If the above command is successful, you will see the output similar to the one as shown below:

4. Set Python Variables

Now, set/include the following Python related variables in the “.bash_profile” file and save it.

$ vi ~/.bash_profile
export PYTHONHOME=/home/oracle/python312
export PATH=$PYTHONHOME/bin:$PATH
export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH

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.

Once you saved the file, reload the “.bash_profile” content using source command.

$ source ~/.bash_profile

Create a symbolic link in your $PYTHONHOME/bin directory.
You need to link it to your Python 3.12 executable, which you can do with the following commands:

$ cd $PYTHONHOME/bin
$ ln -s python3.12 python3

6. Upgrade the PIP

pip will return warnings during above package installations if the latest version is not installed. So, to upgrade the pip, run the following command:

$ python3 -m pip install --upgrade pip

If the PIP is already upgraded, you will see a message that “Requirement already satisfied” otherwise it will upgrade the PIP to the latest version.

7. Invoke Python and Test Whether the Installation is Properly Done

$ python3
\>>> import sys
\>>> print(sys.executable)
\>>> quit()

If the “python3” is not getting invoked or erring out, or if the Python commands such as “import sys” or “print(sys.executable)” is not working or erring out, then it means that the Python was not installed properly. So, please go through all the above steps once again and verify where it fails or erring out and fix it. If all the above commands are successful, you will see the output similar to the one below:

The command “print(sys.executable)” should show the newly installed python 3.12 location.

Thanks for reading this article. Hope this helped you to progress your work!.