Python – Install cx_Oracle

I want to query data from an Oracle database from a Python program and this could be done by using the cx_Oracle Python package. This package required some Oracle package pre-requisites so it cannot be installed thru pip directly.

The following steps are done on a Centos 7 machine with Python 2.7.

1. Download and install the following from Oracle.

  • oracle-instantclient11.2-basic
  • oracle-instantclient11.2-devel
  • oracle-instantclient11.2-sqlplus

 

2. The installed client should be located at /usr/lib/oracle/11.2/client64.
 

3. Create the /etc/ld.so.conf.d/oracle.conf.

/usr/lib/oracle/11.2/client64/lib

 

4. Create the /etc/profile.d/oracle-client.sh.

export ORACLE_HOME=/usr/lib/oracle/11.2/client64/bin; export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:\$ORACLE_HOME/bin:\$ORACLE_HOME/lib

 

5. Quit the shell and login again.
 

6. Verify the $ORACLE_HOME and $LD_LIBRARY_PATH.

env | grep ORACLE
env | grep LD_LIBRARY_PATH

 

7. If the above env variables exists, you can install the cx_Oracle package thru pip.

pip install cx_Oracle

 

Done =)

Reference: StackOverflow – install cx_oracle for python

Advertisements

One thought on “Python – Install 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s