First step: Download and install Cx_oracle
: http://sourceforge.net/projects/cx-oracle/files/5.1.2/, download the cx_oracle RMP installation file, note that the download version is best aligned with the Oracle, Python environment, My current environment is Oracle 11g and Python2.7, so the download is cx_oracle-5.1.2-11g-py27-1.x86_64.rpm.
Do not need to press RPM to install, direct decompression to remove the cx_oracle.so file (only need this), copied to the Python environment Dist-packages directory, my machine is/usr/local/lib/python2.7/ Dist-packages/.
Decompression command:
file. rpm | Cpio-div
Step two: Download and install the Oracle Instant Client
: http://www.oracle.com/technetwork/indexes/downloads/index.html, from the database column of the Instant client link to enter, according to the current system selection of the corresponding download, I chose instant Client for Linux x86-64
Unzip the download file oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm, actually only need the so shared library file, copy all so files to a separate path, I will copy them to/opt/ Oracle-instantclient11.2/lib.
There should be 5 files:
pwd/opt/oracle-instantclient11. 2/liblslibclntsh.so. 11.1 Libnnz11.so libocci.so. 11.1 libociei.so libocijdbc11.so
Step three: Check and install Libaio1
sudo Install Libaio1
Fourth Step: Configure environment variables
CD ~sudo vim. BASHRC
Put the export ld_library_path= $LD _library_path:/opt/oracle-instantclient11.2/lib This line in the inside, save the exit.
Finally: Test
$ python Import = cx_oracle.connect (' username/[email protected]:p ort/= Conn.cursor ()
A simple application:
#!/usr/bin/python#Coding=utf-8Importcx_oracledefHello ():" "Hello cx_oracle Example: 1) Print database version information. 2) query the table data." "Conn= Cx_oracle.connect ("Codomain/[email Protected]:1521/oracle1") cur=conn.cursor ()Try: Print "Oracle version:%s"%conn.versionPrint "Table test rows:"Cur.execute ('SELECT * FROM Test') forRowinchcur:PrintRowfinally: Cur.close () conn.close () Hello ( )
Original Reference website:
http://www.laonan.net/blog/54/http://aofengblog.blog.163.com/blog/static/6317021201157111336764/