【问题标题】:cx_Oracle: distutils.errors.DistutilsSetupError: cannot locate Oracle include filescx_Oracle: distutils.errors.DistutilsSetupError: 找不到 Oracle 包含文件
【发布时间】:2014-08-24 08:29:14
【问题描述】:

我需要在 Linux (Linux 2.6.18-371.1.2.el5 i686) 上为 Python 2.5 安装 cx_Oracle。我已经安装了 Oracle 客户端 10.2.0.4。

我尝试过以下操作: 1.从http://sourceforge.net/projects/cx-oracle/files/下载cx_Oracle tar.gz。 我不知道列出的哪个版本适用于 python 2.5 和 Oracle 客户端 10.2.0.4,所以试试 cx_Oracle-5.1.tar.gz。解压焦油, 转到解压缩的文件夹并运行 python setup.py install。我得到了错误:

Traceback (most recent call last):
File "setup.py", line 187, in <module>
raise DistutilsSetupError("cannot locate Oracle include files")
distutils.errors.DistutilsSetupError: cannot locate Oracle include files

在 .bash_profile 我设置了 oracle 路径:

export ORACLE_HOME=/usr/oracle/10.2.0.4/client
export PATH=$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

如何修复此类错误,也许我需要另一个版本的 cx_Oracle tar?

  1. 运行 pip install cx_Oracle。出现错误:

下载/解压 cx-Oracle

Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement cx-Oracle
No distributions at all found for cx-Oracle

有人可以告诉我正确的解决方案吗?

更新 在回应建议后,我收到以下错误:

...
cx_Oracle.c:496: warning: passing argument 3 of âPyModule_AddIntConstantâ makes integer from  pointer without a cast
cx_Oracle.c:497: error: âOCI_UCBTYPE_EXITâ undeclared (first use in this function)
cx_Oracle.c:497: warning: passing argument 3 of âPyModule_AddIntConstantâ makes integer from pointer without a cast
cx_Oracle.c:498: error: âOCI_UCBTYPE_REPLACEâ undeclared (first use in this function)
cx_Oracle.c:498: warning: passing argument 3 of âPyModule_AddIntConstantâ makes integer from pointer without a cast
error: command 'gcc' failed with exit status 1

【问题讨论】:

    标签: linux oracle python-2.5 cx-oracle


    【解决方案1】:

    当您运行 setup.py 时,它将检查您的 ORACLE_HOME 上的任何这些文件夹。

    possibleIncludeDirs = ["rdbms/demo", "rdbms/public", "network/public",
            "sdk/include"]
    

    此外,即时客户端有时会将包含文件(例如 oci.h)放在 /usr/include/oracle//client 中,如果 ORACLE_HOME 下没有“包含”目录,请创建指向它的符号链接。

    sudo ln -s /usr/include/oracle/11.2/client $ORACLE_HOME/include
    

    您好像错过了Client SDK

    【讨论】:

    • 我尝试创建符号链接,但没有帮助,但我尝试在 /usr/oracle/10.2.0.4/client/network 中添加空文件夹包含。这个修复了错误,但我得到了新的,请在更新的问题中查看详细信息
    • @khris 尝试下载 sdk 并在您的客户端上解压,它应该会创建 sdk/include 文件夹。我添加了答案的链接。
    • 能否请您提供直接链接,因为在客户端 SDK 页面中我看到了很多东西,例如内容管理 SDK,但不知道我需要下载什么。谢谢
    • 我无法直接链接到该文件,请转到 oracle.com/technetwork/topics/linuxsoft-082809.html 并为您的 oracle 版本搜索“Instant Client Package - SDK: Additional header files and an example makefile for development Oracle applications with Instant Client” .
    • 谢谢!以下命令帮助了我:sudo mkdir $ORACLE_HOME/sdk/sudo ln -s /usr/include/oracle/12.1/client $ORACLE_HOME/sdk/include
    【解决方案2】:

    确保为您的操作系统安装即时客户端 sdk。

    http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

    【讨论】:

      【解决方案3】:
      1. 安装oracle_client_basic

        oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
        
      2. 使用 pip 安装

        python -m pip install cx_Oracle
        
      3. 添加 ldconfig

        1. 查找您的客户位置,例如:/u01/app/oracle/product/11.2.0/client_1/lib
        2. vi /etc/ld.so.conf.d/oracle.conf

          将此位置添加到其中:

          /u01/app/oracle/product/11.2.0/client_1/lib
          
        3. ldconfig
      4. import cx_oracle

      【讨论】:

        【解决方案4】:

        确保您的路径中存在客户端 sdk。

        我还必须将它添加到我的 .bash_rc 中

        export DYLD_LIBRARY_PATH=$ORACLE_HOME
        

        除此之外,Python 2.7 不附带 Python.h,Python.h 默认在 Python 3.4 中可用。所以我也建议安装 python-devel 包

        yum install python-devel
        

        这应该可以解决问题。

        【讨论】:

          猜你喜欢
          • 2013-03-22
          • 2018-02-28
          • 2018-06-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-05
          • 2011-10-22
          • 2012-11-01
          相关资源
          最近更新 更多