cx_Oracle.DatabaseError:DPI-1047:无法加载64位Oracle客户端库:“dlopen(libclntsh.dylib,1):找不到图像”

时间:2017-09-07 14:10:31

标签: python python-2.7 cx-oracle

我正在尝试设置cx_Oracle以使用Python。

我正在使用

  • Python 2.7.10,64位
  • cx_Oracle版本6.0.2
  • MacOS Sierra 10.12.6

我设置了以下环境变量:

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}

以下是我的尝试:

  1. 以管理员身份安装
  2. sudo python setup.py build
  3. sudo python setup.py install
  4. 当我尝试执行一个简单的脚本来检查Oracle连接时,我能够通过sqlplus成功连接。

    以下是我收到的错误:

      

    cx_Oracle.DatabaseError:DPI-1047:无法加载64位Oracle客户端库:“dlopen(libclntsh.dylib,1):找不到图像”。请参阅https://oracle.github.io/odpi/doc/installation.html#macos获取帮助

6 个答案:

答案 0 :(得分:5)

我的Ubuntu 16.04(64位)解决方案

official guide tl; dr:

1)下载instantclient-basic-linux.x64-12.2.0.1.0.zip

2)将其解压缩到/ opt / oracle目录:

 
elasticParams.Filters.Aggregate(new QueryContainer(), (c, s) => c && +q.Term(p => p.Name, s), c => c);

3)安装 libaio

$ sudo mkdir -p /opt/oracle
$ cd /opt/oracle
$ unzip ~/Downloads/instantclient-basic-linux.x64-12.2.0.1.0.zip

4)编辑 oracle-instantclient.conf 文件,如下所示:

$ sudo apt-get install libaio1

答案 1 :(得分:1)

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

答案 2 :(得分:0)

要扩展@ anthony-tuininga的回答:错误消息中的URL包含要遵循的步骤。请参阅https://oracle.github.io/odpi/doc/installation.html#macos具体确保Oracle客户端库位于〜/ lib或/ usr / local / lib中。 不要设置DYLD_LIBRARY_PATH或LD_LIBRARY_PATH或ORACLE_HOME。

答案 3 :(得分:0)

对我

source ~/.profile

在安装过程中是跳过的步骤

答案 4 :(得分:0)

我按照这些步骤操作,它在 MacOS 中对我有用。

按照以下链接中的说明下载适用于 MacOS 的 Oracle Instant Client

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

并将以下内容添加到位于主目录中的 ./bash_profile 文件中。

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

并使用 conda 安装了 cx_Oracle 库。

https://anaconda.org/anaconda/cx_oracle

这里还有一个例子,可以在 Jupyter Notebook 中尝试验证它是否正确安装。

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

答案 5 :(得分:-1)

在Virtualenv中安装cx_Oracle

前提条件。

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

通过

中的说明https://oracle.github.io/odpi/doc/installation.html#macos安装的Oracle客户端
/opt/oracle/instantclient_12_1

添加到〜/ .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

尝试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)
   ...:     
相关问题