I am trying to set up cx_Oracle
to work with Python.
I am using
cx_Oracle
version 6.0.2I set the following environment variables:
export ORACLE_HOME="/Volumes/DATA/Programs/PY/instantclient_12_1"
export DYLD_LIBRARY_PATH="$ORACLE_HOME:$DYLD_LIBRARY_PATH"
export LD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME
export ORACLE_SID=edocd
export TNS_ADMIN=/Volumes/DATA/Programs/PY/instantclient_12_1/network/admin
export TWO_TASK=${ORACLE_SID}
Here is what I tried:
sudo python setup.py build
sudo python setup.py install
When I tried to execute a simple script to check the Oracle connection I was able to connect successfully via sqlplus
.
Here is the error I receive:
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help
link ${your_instantclient_folder}
-> ${oracle_home}/lib
cd ${ORACLE_HOME};
unzip instantclient-basic-macos.x64-x.x.x.zip
ln -s instantclient_X_X lib
reference
Install cx_Oracle in Virtualenv
Preconditions.
Python 2.7.10, 64-bit
cx_Oracle version 6.0.2
MacOS Sierra 10.12.6
Oracle client installed by instructions https://oracle.github.io/odpi/doc/installation.html#macos in
/opt/oracle/instantclient_12_1
Add to your ~/.bash_profile:
export ORACLE_HOME=/opt/oracle/instantclient_12_1
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$ORACLE_HOME:$PATH
Try Virtualenv
1. virtualenv ~/venv
2. source ~/venv/bin/activate
3. pip install IPython (Optional. I prefer IPython)
4. pip install cx_Oracle
(venv) ~$ pip install cx_Oracle
Collecting cx_Oracle
Installing collected packages: cx-Oracle
Successfully installed cx-Oracle-6.0.2
(venv) ~$ IPython
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
Type "copyright", "credits" or "license" for more information.
IPython 5.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import cx_Oracle
In [2]: con = cx_Oracle.connect('system/manager@orasrv/orcl')
In [3]: cur = con.cursor()
...:
...: select = ("SELECT * FROM tbl1")
...: cur.execute(select)
...:
Out[3]: <cx_Oracle.Cursor on <cx_Oracle.Connection to system@orasrv/orcl>>
In [4]: for row in cur:
...: print(row)
...:
My solution for Ubuntu 16.04 (64bit)
A tl;dr: of the official guide:
1) Download the instantclient-basic-linux.x64-12.2.0.1.0.zip
2) Extract it to /opt/oracle directory:
$ sudo mkdir -p /opt/oracle
$ cd /opt/oracle
$ unzip ~/Downloads/instantclient-basic-linux.x64-12.2.0.1.0.zip
3) Install libaio package
$ sudo apt-get install libaio1
4) Edit the oracle-instantclient.conf file like so:
$ sudo sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With