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

问题描述 投票:3回答:5

我正在尝试设置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

当我尝试执行一个简单的脚本来检查Oracle连接时,我能够通过sqlplus成功连接。

这是我收到的错误:

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

python python-2.7 cx-oracle
5个回答
6
投票

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

一个人;博士:official guide

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

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

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

3)安装libaio包

$ sudo apt-get install libaio1

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

$ sudo sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig

1
投票

链接${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


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。


0
投票

为了我

source ~/.profile

是安装时跳过的步骤。


-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)
   ...:     
© www.soinside.com 2019 - 2024. All rights reserved.