Cx_oracle: '5. 1.2'
Centos Release 6.2 (final)
Python: 2.7.5
Testing is acceptable.
Link: http://leigh.cudd.li/article/Setting_up_cxOracle_on_CentOS_6
**************************************** **************************************** ************************
Setting up cxoracle on centos 6
Oracle Python Linux 11
Jun 2012
Setting up anything Oracle related is a huge pain. After hunting the web for info with minimal success, I have decided to create a small tutorial to walk through setting up cx_oracle
Connect to Oracle installations.
Prerequisites
If you do not have a oracle.com account, you will unfortunately need to create one to be able to download anything. Once you have your account head to the OS
Selection page and select the appropriate OS, in my case this will be Linux/amd64. on the subsequent page you must downloadBasiclitePackage as well asDevelPackage. I chose the RPM files
As I am running centos 6. x. If you want non-English application support you probably want to installBasicVersion instead of the basiclite, it has multilingual support built in. You may optionally want to installSqlplusPackage
To help with debugging and Connection issues.
Oracle library Installation
I downloaded the RPM files so ill use the RPM command to install the packages as follows
| 1234567 |
[root@devel ~] # cd oracle_files[root@devel oracle_files]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpmPreparing... ########################################### [100%]1:oracle-instantclient11.########################################### [ 33%]2:oracle-instantclient11.########################################### [ 67%]3:oracle-instantclient11.########################################### [100%][root@devel oracle_files]# |
This will install the client under/Usr/lib/Oracle/11.2/client64/By default under centos. Now this path is not listed under the shared library path by default (why doesn't this get setup
By default ?), So we must add it. Create the following file:/Etc/lD. So. conf. d/oracle. confWith the following contents, adjusted accordingly to your installation:
| 1 |
/usr/lib/oracle/11.2/client64/lib |
With that in place we can now enable the shared library path system wide as follows:
| 1 |
[root@devel ~]# ldconfig |
To verify the library path installation you can try and run the sqlplus client. If it fails to start then you have a problem and shocould look into any mistakes that may have occurred during the installation process.
| 123456 |
[root@devel ~]# PATH=$PATH:/usr/lib/oracle/11.2/client64/bin # place in ~/.bashrc for a permanent setup[root@devel ~]# sqlplusSQL*Plus: Release 11.2.0.3.0 Production on Mon Jun 11 16:57:40 2012Copyright (c) 1982, 2011, Oracle. All rights reserved. |
Python library Installation
With the Oracle libraries installed we can now begin installing the python connector cx_oracle. I will be building a RPM file from the source
Rpm. If you are not using centos, or don't want to build a rpm for whatever reason, then go ahead and grab the source tarball instead.
Building and installing from source RPM:
| 12345678 |
[root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.src.rpm1:cx_Oracle ########################################### [100%][root@devel ~]# cd ~/rpmbuild/SPECS[root@devel ~]# ORACLE_HOME=/usr/lib/oracle/11.2/client64/ rpmbuild -ba cx_Oracle.spec[root@devel ~]# cd ../RPMS/x86_64[root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.x86_64.rpmPreparing... ########################################### [100%]1:cx_Oracle ########################################### [100%] |
Or building and installing from source tarball
| 1234 |
tar xvfz cx_Oracle.tar.gzcd cx_Oracle.tar.gzORACLE_HOME=/usr/lib/oracle/11.2/client64/ python setup.py buildORACLE_HOME=/usr/lib/oracle/11.2/client64/ python setup.py install |
Verification
To easily test if the installation has succeded run the following 1 liner, if no errors occur then your installation went OK.
| 1 |
[root@devel x86_64]# python -c 'import cx_Oracle' |