【问题标题】:cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found"cx_Oracle.DatabaseError:DPI-1047:无法加载 64 位 Oracle 客户端库:“dlopen(libclntsh.dylib, 1): image not found”
【发布时间】:2017-09-07 14:10:31
【问题描述】:

我正在尝试设置 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): image not found”。请参阅https://oracle.github.io/odpi/doc/installation.html#macos 寻求帮助

【问题讨论】:

  • 您是否按照错误消息中的链接中的说明进行操作?

标签: python python-2.7 cx-oracle


【解决方案1】:

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

official guide:

tl;dr:

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

【讨论】:

  • 感谢分享,但问题是关于 macOS 的。解决方案与 Linux 不同。
【解决方案2】:

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

    在 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
    

    试试虚拟环境

    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)
       ...:     
    

    【讨论】:

    • 对于当前的 macOS 版本,SIP 将停止从子 shell 读取 DYLD_LIBRARY_PATH,因此它并没有真正的帮助,也不需要设置。 LD_LIBRARY_PATH 在 macOS 上是多余的。对于 Oracle Instant Client(和 cx_Oracle 6),您不应该设置 ORACLE_HOME。
    【解决方案4】:

    扩展@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。

    【讨论】:

    • 这确实有帮助。 [Ubuntu 16.04 64 位 | PyCharm 2017.3CE]
    【解决方案5】:

    对我来说

    source ~/.profile

    是安装时跳过的步骤

    【讨论】:

      【解决方案6】:

      我按照这些步骤操作,它在 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

      【讨论】:

      • 永远不要使用 Instant Client 设置 ORACLE_HOME。它有不同的目的。由于在 macOS 上设置库加载路径变量被“破坏”,通常我不设置任何环境变量(PATH 除外)而是将其添加到我的代码中:import sys, os if sys.platform.startswith("darwin"): cx_Oracle.init_oracle_client(lib_dir=os.environ.get("HOME")+"/Downloads/instantclient_19_8")
      猜你喜欢
      • 2019-01-06
      • 1970-01-01
      • 2019-09-13
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      • 2021-11-08
      • 2019-10-10
      相关资源
      最近更新 更多