INSTALL PYTHON MODULE CX_ORACLE FOR ORACLE DATABASE

If we want to write scripts in python for oracle database, we have an efficient module which acts as an api for performing automation or machine learning anomaly detections in oracle database.

In this article, we will see how to install the package

First install pip3 latest version which acts similar to yum in linux which will install scientific libraries specifically related to python libraries or modules.

In linux it is simple to install pip using yum. Follow the below steps!

[root@orcl19x oracle]# yum install python3-pip
Loaded plugins: langpacks, ulninfo
Resolving Dependencies
--> Running transaction check
---> Package python3-pip.noarch 0:9.0.3-8.el7 will be installed
--> Processing Dependency: python(abi) = 3.6 for package: python3-pip-9.0.3-8.el7.noarch
--> Processing Dependency: python3-setuptools for package: python3-pip-9.0.3-8.el7.noarch
--> Processing Dependency: /usr/bin/python3 for package: python3-pip-9.0.3-8.el7.noarch
--> Running transaction check
---> Package python3.x86_64 0:3.6.8-18.0.3.el7 will be installed
--> Processing Dependency: python3-libs(x86-64) = 3.6.8-18.0.3.el7 for package: python3-3.6.8-18.0.3.el7.x86_64
--> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python3-3.6.8-18.0.3.el7.x86_64
---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed
--> Running transaction check
---> Package python3-libs.x86_64 0:3.6.8-18.0.3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package                       Arch              Version                     Repository             Size
=========================================================================================================
Installing:
 python3-pip                   noarch            9.0.3-8.el7                 ol7_latest            1.6 M
Installing for dependencies:
 python3                       x86_64            3.6.8-18.0.3.el7            ol7_latest             70 k
 python3-libs                  x86_64            3.6.8-18.0.3.el7            ol7_latest            6.9 M
 python3-setuptools            noarch            39.2.0-10.el7               ol7_latest            628 k

Transaction Summary
=========================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 9.3 M
Installed size: 47 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): python3-3.6.8-18.0.3.el7.x86_64.rpm                                        |  70 kB  00:00:00
(2/4): python3-pip-9.0.3-8.el7.noarch.rpm                                         | 1.6 MB  00:00:00
(3/4): python3-setuptools-39.2.0-10.el7.noarch.rpm                                | 628 kB  00:00:02
(4/4): python3-libs-3.6.8-18.0.3.el7.x86_64.rpm                                   | 6.9 MB  00:00:03
---------------------------------------------------------------------------------------------------------
Total                                                                    2.5 MB/s | 9.3 MB  00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python3-setuptools-39.2.0-10.el7.noarch                                               1/4
  Installing : python3-pip-9.0.3-8.el7.noarch                                                        2/4
  Installing : python3-3.6.8-18.0.3.el7.x86_64                                                       3/4
  Installing : python3-libs-3.6.8-18.0.3.el7.x86_64                                                  4/4
  Verifying  : python3-libs-3.6.8-18.0.3.el7.x86_64                                                  1/4
  Verifying  : python3-3.6.8-18.0.3.el7.x86_64                                                       2/4
  Verifying  : python3-setuptools-39.2.0-10.el7.noarch                                               3/4
  Verifying  : python3-pip-9.0.3-8.el7.noarch                                                        4/4

Installed:
  python3-pip.noarch 0:9.0.3-8.el7

Dependency Installed:
  python3.x86_64 0:3.6.8-18.0.3.el7                    python3-libs.x86_64 0:3.6.8-18.0.3.el7
  python3-setuptools.noarch 0:39.2.0-10.el7

Complete!

After pip3 installation , we can install cx_oracle using pip directly

[root@orcl19x oracle]# pip3 install cx_oracle
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting cx_oracle
  Downloading https://files.pythonhosted.org/packages/77/c0/72e79c45947ec1c41d89507f546a22658c2603edcfe2c445738725ca2bbb/cx_Oracle-8.2.1-cp36-cp36m-manylinux1_x86_64.whl (818kB)
    100% |████████████████████████████████| 819kB 1.0MB/s
Installing collected packages: cx-oracle
Successfully installed cx-oracle-8.2.1

Invoke python3.6 and import the module and enjoy coding !! If you have multiple versions of python installed, then you can again install the same package and you will get a message saying that the module is installed in a specific python version directory. You can find out using this way.

[root@orcl19x oracle]# pip3 install cx_Oracle
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: cx_Oracle in /usr/local/lib64/python3.6/site-packages

[root@orcl19x oracle]# type python3.6
python3.6 is hashed (/bin/python3.6)
[root@orcl19x oracle]# type python3.6
python3.6 is hashed (/bin/python3.6)

[root@orcl19x oracle]# python3.6
Python 3.6.8 (default, Mar  9 2021, 15:08:44)
[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 cx_Oracle

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s