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

sam*_*ena 5 python cx-oracle python-2.7

我正在尝试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}
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

  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以获得帮助

Ser*_*tov 6

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

一个TL;博士:在的官方指南

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
Run Code Online (Sandbox Code Playgroud)

3)安装libaio软件包

$ sudo apt-get install libaio1
Run Code Online (Sandbox Code Playgroud)

4)像这样编辑oracle-instantclient.conf文件:

$ sudo sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig
Run Code Online (Sandbox Code Playgroud)


小智 1

在 Virtualenv 中安装 cx_Oracle

前提条件。

Python 2.7.10, 64-bit
cx_Oracle version 6.0.2
MacOS Sierra 10.12.6
Run Code Online (Sandbox Code Playgroud)

Oracle客户端按照https://oracle.github.io/odpi/doc/installation.html#macos中的指令安装

/opt/oracle/instantclient_12_1
Run Code Online (Sandbox Code Playgroud)

添加到您的 ~/.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
Run Code Online (Sandbox Code Playgroud)

尝试虚拟环境

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)
   ...:     
Run Code Online (Sandbox Code Playgroud)