使用MacOSX导入cx_Oracle(python)

使用MacOSX导入cx_Oracle(python),python,macos,cx-oracle,Python,Macos,Cx Oracle,在python脚本中导入cx_Oracle失败 我已经安装了cx_Oracle,使用“pip install cx_Oracle”-运行良好,报告已安装 现在,当我尝试: import cx_Oracle 我得到以下错误 Traceback (most recent call last): File "reader.py", line 9, in <module> import cx_Oracle ImportError: dlopen(/Library/Python/

在python脚本中导入cx_Oracle失败

我已经安装了cx_Oracle,使用“pip install cx_Oracle”-运行良好,报告已安装

现在,当我尝试:

import cx_Oracle
我得到以下错误

Traceback (most recent call last):
  File "reader.py", line 9, in <module>
    import cx_Oracle
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
  Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/cx_Oracle.so
甲骨文10.2

$ sqlplus -version    
SQL*Plus: Release 10.2.0.4.0 - Production
此外,我的ORACLE_主文件夹中根本没有/bin目录,我只安装了即时客户端和SDK

神谕

$ pip freeze
PyRSS2Gen==1.0.0
...
cx-Oracle==5.1.1
(在安装cx_Oracle方面发现了很多问题,但没有一个问题-谢谢)

卸载所有内容

然后安装oracle instant client:

然后使用pip安装cx\U oracle

然后将路径设置为指向32位版本的oracle

  • 编辑主目录中的.profile文件,并使用以下行将路径添加到oracle bin主目录:
  • 导出路径=$PATH:/usr/local/lib/instantclient/

它可以工作…

我今天遇到了这个问题,通过将InstantClient二进制文件中引用的库的路径更改为文件系统上的实际位置,我能够解决这个问题。 这个博客提供了详细的解释和调整所有二进制文件的脚本。唯一的问题是它使用@executable_path,这似乎不再适用于Python2.7和El Capitan(我不确定是什么导致了安全异常)。用实际路径替换@executable_path效果很好

总而言之,使其工作的步骤如下:

  • 将InstantClient安装到/usr/local/InstantClient\u 11\u 2
  • 确保您使用的cx_Oracle.so共享对象位于/Library/Python/2.7/site-packages/cx_Oracle.so
  • 将以下脚本复制到/usr/local/instantclient_11_2

    #!/bin/sh
    # script to change the dynamic lib paths and ids for oracle instant client
    # exes and libs
    (echo /Library/Python/2.7/site-packages/cx_Oracle.so ; find . -maxdepth 1 -type f \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print ) | while read exe
    do
        echo adjusting executable $exe
        baseexe=`basename $exe`
        otool -L $exe | awk '/oracle/ {print $1}' | while read lib
        do
            echo adjusting lib $lib
            baselib=`basename $lib`
            if [ "$baseexe" = "$baselib" ]
            then
                echo changing id to $baselib for $exe
                install_name_tool -id $baselib $exe
            else
                echo changing path id for $lib in $exe
                install_name_tool -change $lib /usr/local/instantclient_11_2/$baselib $exe
            fi
        done
    done
    
    • 使用root权限运行脚本

我可能有它,如果它是真的,我会发布我自己的答案。我正在查看setup.py脚本,注意到它使用文件夹名称猜测版本。我已经在10.1文件夹中安装了10.2,也许这就是问题所在。好的,我手动安装了CX_ORACLE,而不是使用pip,现在我有一点不同,但基本上是相同的问题。文件“reader.py”,第9行,导入cx_Oracle文件“build/bdist.macosx-10.7-intel/egg/cx_Oracle.py”,第7行,在引导程序ImportError:dlopen(/Users/me/.python-egs/cx_-Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_-Oracle.so,2)中的第6行:Symbol not found:_ociattarget和“将mac os设置为使用32位模式”的神奇词语是什么?我所做的是安装了32位模式的oracle版本,并指向该目录的路径。首先如何在mac上安装oracle客户端?导出VERSIONER_PYTHON_preference_32_bit=yes
#!/bin/sh
# script to change the dynamic lib paths and ids for oracle instant client
# exes and libs
(echo /Library/Python/2.7/site-packages/cx_Oracle.so ; find . -maxdepth 1 -type f \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print ) | while read exe
do
    echo adjusting executable $exe
    baseexe=`basename $exe`
    otool -L $exe | awk '/oracle/ {print $1}' | while read lib
    do
        echo adjusting lib $lib
        baselib=`basename $lib`
        if [ "$baseexe" = "$baselib" ]
        then
            echo changing id to $baselib for $exe
            install_name_tool -id $baselib $exe
        else
            echo changing path id for $lib in $exe
            install_name_tool -change $lib /usr/local/instantclient_11_2/$baselib $exe
        fi
    done
done