简体   繁体   中英

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

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

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)
   ...:     

To expand on @anthony-tuininga's answer: the URL in the error message has the steps to follow. See https://oracle.github.io/odpi/doc/installation.html#macos Specifically make sure the Oracle client libraries are in ~/lib or /usr/local/lib. Don't set DYLD_LIBRARY_PATH or LD_LIBRARY_PATH or ORACLE_HOME.

For me

source ~/.profile

was the skipped step while installing.

I followed these steps and it worked for me in MacOS.

Followed instruction inside the following link to download Oracle Instant Client for MacOS

https://www.oracle.com/database/technologies/instant-client/downloads.html

And added following into ./bash_profile file located inside home directory.

export ORACLE_HOME= <path to Oracle Instant Client folder>(I used instantclient_19_8)
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$ORACLE_HOME:$PATH

And installed cx_Oracle library using conda.

https://anaconda.org/anaconda/cx_oracle

Also here's an example to try in Jupyter Notebook to verify that it installed correctly.

https://krinkere.github.io/krinkersite/connect_to_oracle_via_python.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM