Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Install cx_Oracle on Oracle Linux 7 with the Instant Client 12.2

Sergio-OracleMar 15 2017 — edited Mar 15 2017

Introduction

cx_Oracle is a module that enables access to Oracle Database and conforms with the Python database API specification. The module works with Oracle Database 11g and 12c and both Python 2.x and 3.x. This post covers the steps to install and set up cx_Oracle 5.3 with the default Python 2.7.5 on Oracle Linux 7 using a Python virtual environment. In an earlier post I covered how to install cx_Oracle with Python 3.5 from Software Collection Library.

Steps

These are the steps to install cx_Oracle.  I used an Oracle Linux 7.3 Vagrant box as a starting point.

  1. Download and install Oracle Instant Client 12.2 and the Instant Client SDK RPMs
  2. Install Python Virtual Environment RPM, if needed
  3. Create and activate a virtual environment
  4. Install cx_Oracle using pip

Download and Install Oracle Instant Client

Oracle Instant Client enables development and production deployment of Oracle Database applications. It is used for popular languages and environments including Node.js, PHP, and Python. Download the Instant Client RPM for Oracle Linux x86-64. Install the RPM as root:

$ sudo rpm -ihv oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm

Preparing...                          ################################# [100%]

Updating / installing...

   1:oracle-instantclient12.2-basic-12################################# [100%]

To build cx_Oracle, you'll need the instant client SDK header files as well. From the same download page as above, get the Instant Client Package - SDK RPM and install it:

$ sudo rpm -ihv oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm

Preparing...                          ################################# [100%]

Updating / installing...

   1:oracle-instantclient12.2-devel-12################################# [100%]

Install Python Virtual Environment

For this installation I will use a Python Virtual Environment.  In the Python 2.7.x documentation, a virtual environment is described as:

A cooperatively isolated runtime environment that allows Python users and applications to install and upgrade Python distribution packages without interfering with the behaviour of other Python applications running on the same system.

Use Yum to install python-virtualenv, if it's not already.

$ sudo yum install python-virtualenv

Create and Activate Virtual Environment

Create a virtual environment called my275env. You will see Setuptools and pip are installed during this process.

$ python -m virtualenv my275env

Activate the virtual environment. The bash prompt will change to indicate you are in the my275env virtualenvironment:

$ . my275env/bin/activate

(my275env) $

Install cx_Oracle

With the instant client and the SDK header files installed, there is no need to set ORACLE_HOME or any PATH environment variables.

(my275env) $ python -m pip install cx_Oracle

You should see output that ends as follows. cx_Oracle is now installed and you are ready to develop!

Successfully installed cx-Oracle

Cleaning up...

References

Comments
Post Details
Added on Mar 15 2017
0 comments
6,534 views