Python cx_Oracle.DatabaseError: DPI-1047: 无法加载 64 位 Oracle 客户端库:“dlopen(libclntsh.dylib, 1): image not found”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46098562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found"
提问by samarth saxena
I am trying to set up cx_Oracle
to work with Python.
我正在尝试设置cx_Oracle
以使用 Python。
I am using
我在用
- Python 2.7.10, 64-bit
cx_Oracle
version 6.0.2- MacOS Sierra 10.12.6
- Python 2.7.10,64 位
cx_Oracle
版本 6.0.2- MacOS 塞拉利昂 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
- 以管理员身份安装
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
.
当我尝试执行一个简单的脚本来检查 Oracle 连接时,我能够通过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#macosfor help
cx_Oracle.DatabaseError:DPI-1047:无法加载 64 位 Oracle 客户端库:“dlopen(libclntsh.dylib, 1):找不到图像”。请参阅https://oracle.github.io/odpi/doc/installation.html#macos寻求帮助
回答by Serzhan Akhmetov
My solution for Ubuntu 16.04 (64bit)
我的 Ubuntu 16.04(64 位)解决方案
A tl;dr:of the official guide:
一个TL;博士:在的官方指南:
1) Download the instantclient-basic-linux.x64-12.2.0.1.0.zip
1)下载instantclient-basic-linux.x64-12.2.0.1.0.zip
2) Extract it to /opt/oracle directory:
2) 解压到 /opt/oracle 目录:
$ sudo mkdir -p /opt/oracle
$ cd /opt/oracle
$ unzip ~/Downloads/instantclient-basic-linux.x64-12.2.0.1.0.zip
3) Install libaiopackage
3) 安装libaio包
$ sudo apt-get install libaio1
4) Edit the oracle-instantclient.conffile like so:
4)像这样编辑oracle-instantclient.conf文件:
$ sudo sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig
回答by namiha
回答by Kishor Pawar
For me
为了我
source ~/.profile
source ~/.profile
was the skipped stepwhile installing.
是安装时跳过的步骤。
回答by AlexZ
Install cx_Oracle in Virtualenv
在 Virtualenv 中安装 cx_Oracle
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#macosin
Oracle 客户端安装说明https://oracle.github.io/odpi/doc/installation.html#macosin
/opt/oracle/instantclient_12_1
Add to your ~/.bash_profile:
添加到您的 ~/.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
尝试 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)
...:
回答by Christopher Jones
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#macosSpecifically 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.
扩展@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。