cx_Oracle:distutils.errors.DistutilsSetupError:无法找到Oracle包含文件

20

我需要在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
4个回答

14
当您运行setup.py时,它会检查ORACLE_HOME上是否存在这些文件夹中的任何一个。
possibleIncludeDirs = ["rdbms/demo", "rdbms/public", "network/public",
        "sdk/include"]

如果ORACLE_HOME目录下没有'include'文件夹,那么即时客户端有时会将包含文件(如oci.h)放置在/usr/include/oracle//client中,请创建符号链接以解决此问题。

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

看起来您缺少客户端SDK


1
我尝试创建符号链接,但没有帮助。不过,我尝试在 /usr/oracle/10.2.0.4/client/network 中添加一个空文件夹。这解决了错误,但是我遇到了新问题,请参见更新的问题详情。 - khris
@khris 请尝试下载SDK并在客户端上进行提取,它应该会创建sdk/include文件夹。我已经在答案中添加了链接。 - fn.
请问您能否提供直接链接?因为在客户端SDK页面上,我看到了很多东西,比如内容管理SDK,但不知道我需要下载哪一个。谢谢。 - khris
我无法直接链接到文件,请前往http://www.oracle.com/technetwork/topics/linuxsoft-082809.html,并搜索“Instant Client Package - SDK:使用Instant Client开发Oracle应用程序的附加头文件和示例makefile”,以获取您的Oracle版本。 - fn.
1
谢谢!以下命令帮助了我:sudo mkdir $ORACLE_HOME/sdk/ sudo ln -s /usr/include/oracle/12.1/client $ORACLE_HOME/sdk/include - Dennis Golomazov
我已经有了SDK,但仍然遇到相同的错误。请参见https://dev59.com/4o3da4cB1Zd3GeqPuQza。 - Zoltan Fedor

1
  1. Install oracle_client_basic

    oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
    
  2. Using pip install

    python -m pip install cx_Oracle
    
  3. Adding ldconfig

    1. Find your client location, for example: /u01/app/oracle/product/11.2.0/client_1/lib
    2. vi /etc/ld.so.conf.d/oracle.conf

      Add this location into it:

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

1

0

确保你的路径中有客户端SDK。

另外,我还需要将这个添加到我的.bash_rc文件中。

export DYLD_LIBRARY_PATH=$ORACLE_HOME

此外,Python 2.7没有默认安装Python.h,而Python 3.4则有。因此,我建议您安装python-devel软件包。
yum install python-devel

那应该解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接