Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found"

I am trying to set up cx_Oracle to work with Python.

I am using

  • Python 2.7.10, 64-bit
  • cx_Oracle version 6.0.2
  • MacOS Sierra 10.12.6

I 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:

  1. Installed as Administrator
  2. sudo python setup.py build
  3. 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

like image 557
samarth saxena Avatar asked Sep 07 '17 14:09

samarth saxena


3 Answers

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

like image 108
namiha Avatar answered Nov 02 '22 07:11

namiha


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)
   ...:     
like image 30
AlexZ Avatar answered Nov 02 '22 09:11

AlexZ


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
like image 24
Serzhan Akhmetov Avatar answered Nov 02 '22 09:11

Serzhan Akhmetov