问题

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:

Installed as Administrator

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

回答1:

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

回答2:

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

回答3:

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.

回答4:

For me

source ~/.profile

was the skipped step while installing.

回答5:

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

In [4]: for row in cur:

...: print(row)

...:

来源:https://stackoverflow.com/questions/46098562/cx-oracle-databaseerror-dpi-1047-64-bit-oracle-client-library-cannot-be-loaded

更多推荐