23

我正在尝试为 Python 2.6 安装 cx_Oracle,但它失败了。我对 C 或 MS Vis 知之甚少。Studio 的编译器甚至可以自己修复它。

这是命令行上的输出:

C:\pydev\cx_Oracle-5.0.1>C:\python26\python setup.py install
running install
running build
running build_ext
building 'cx_Oracle' extension
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Oracle\instantclient\sdk\include -IC:\p
ython26\include -IC:\python26\PC /Tccx_Oracle.c /Fobuild\temp.win32-2.6-11g\Release\cx_Oracle.obj -DBUILD_VERSION=5.0.1
cx_Oracle.c
c:\pydev\cx_oracle-5.0.1\StringVar.c(392) : warning C4018: '>' : signed/unsigned mismatch
c:\pydev\cx_oracle-5.0.1\StringVar.c(417) : warning C4018: '>' : signed/unsigned mismatch
c:\pydev\cx_oracle-5.0.1\ObjectVar.c(117) : warning C4018: '<' : signed/unsigned mismatch
c:\pydev\cx_oracle-5.0.1\ObjectVar.c(134) : warning C4018: '<' : signed/unsigned mismatch
c:\pydev\cx_oracle-5.0.1\Variable.c(331) : error C2036: 'void *' : unknown size
c:\pydev\cx_oracle-5.0.1\Variable.c(878) : warning C4244: '=' : conversion from 'sb2' to 'sb1', possible loss of data
c:\pydev\cx_oracle-5.0.1\Variable.c(914) : warning C4018: '<' : signed/unsigned mismatch
error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"' failed with exit status 2

有谁知道如何解决这个问题?(我也可能对那个 cl.exe 文件有问题,我想我记得在其他地方看到过这个问题,但我有四台 Windows 机器可能在那里有问题。)。

- - - - - - - - - - - - - - - 编辑 - - - - - - - - - - ---------

我不使用预编译安装程序的原因是因为当我尝试运行该模块时,我得到以下信息:

    Python 2.6.3 (r263rc1:75186, Oct 2 2009, 20:40:30) [MSC v.1500 32 bit (Intel)] on win32
    输入“帮助”、“版权”、“信用”或“许可”以获取更多信息。
    >>> 导入 cx_Oracle
    回溯(最近一次通话最后):
      文件“”,第 1 行,在
    ImportError:DLL 加载失败:找不到指定的模块。

我认为这意味着它没有正确安装。如果有人能告诉我我在这里做错了什么,那也是一个完全可以接受的答案。

----------------------------------------- EDIT2 -------------------- ---------

我已经从Oracle 的 Basic Client版本 11.1.0.7中检索了所有文件。我还没有尝试安装更重要的客户端。我现在正在下载一个。

%ORACLE_HOME%=C:\Oracle\instantclient\ #The directory where the above files have been extracted.

更多信息

  • cx_Oracle 的 setup.py 的当前目录是 C:\pydev\cx_Oracle-5.0.1
  • Python的版本是2.6.3
  • Python 的当前目录是 C:\Python26 -- 访问 python 2.6 -> 在命令行输入 py26 它将映射到 C:\python26\python
4

3 回答 3

19

为什么不使用像Windows Installer (Oracle 10g, Python 2.6)这样的二进制包?

有关其他二进制包,请参见http://cx-oracle.sourceforge.net/


附录(根据要求):您必须确保使用 cx_Oracle :

  • 如果此环境变量不存在,请设置 ORACLE_HOME(请参阅此Oracle 常见问题解答
  • python可以通过添加DLL在PATH环境变量中的文件夹(应该是%ORACLE_HOME%/bin)来找到oraocci11.dllOracle 11g、oraocci10.dllOracle 10g或Oracle 9ioraclient9.dll
  • 使用正确的二进制包(即为正确的 Python/Oracle 版本构建)
于 2009-11-10T21:48:05.237 回答
8

您还需要在您的机器上安装某种类型的 Oracle 客户端,因为 cx_Oracle 只是 Python 和 Oracle 客户端之间的桥梁。有效的 Oracle 客户端包括完整的 Oracle 安装(如 Standard 或 XE)或Instant Client

自述文件

请注意,需要安装 Oracle 客户端(或服务器)才能使用 cx_Oracle。如果您不需要完整客户端安装附带的工具,建议安装更容易安装的 Instant Client。

我以前没有在 Windows 上安装过,但您可能必须设置 ORACLE_HOME 环境变量,以便 cx_Oracle 知道在哪里查找。

于 2009-11-10T22:15:10.357 回答
3

如果您使用 Anaconda Python x64,事情会更容易

conda install -c https://conda.anaconda.org/anaconda cx_oracle

(它将安装正确的 Oracle 客户端)


如果您收到以下错误:

[Anaconda2] C:\Users\User>conda install -c https://conda.anaconda.org/anaconda c
x_oracle
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ......
Solving package specifications: .................
Package plan for installation in environment C:\Anaconda2:

The following NEW packages will be INSTALLED:

    cx_oracle:            5.1.2-py27_0
    oracle-instantclient: 11.2.0.4.0-0

The following packages will be UPDATED:

    conda:                3.19.1-py27_0 --> 4.0.5-py27_0
    pip:                  8.0.2-py27_0  --> 8.1.1-py27_0
    pyyaml:               3.11-py27_2   --> 3.11-py27_3
    setuptools:           19.6.2-py27_0 --> 20.3-py27_0
    wheel:                0.26.0-py27_1 --> 0.29.0-py27_0

Proceed ([y]/n)? y

Unlinking packages ...
An unexpected error has occurred, please consider sending the            |   0%
following traceback to the conda GitHub issue tracker at:

    https://github.com/conda/conda/issues

Include the output of the command 'conda info' in your report.


Traceback (most recent call last):
  File "C:\Anaconda2\Scripts\conda-script.py", line 4, in <module>
    sys.exit(main())
  File "C:\Anaconda2\lib\site-packages\conda\cli\main.py", line 173, in main
    args_func(args, p)
  File "C:\Anaconda2\lib\site-packages\conda\cli\main.py", line 180, in args_fun
c
    args.func(args, p)
  File "C:\Anaconda2\lib\site-packages\conda\cli\main_install.py", line 45, in e
xecute
    install.install(args, parser, 'install')
  File "C:\Anaconda2\lib\site-packages\conda\cli\install.py", line 423, in insta
ll
    plan.execute_actions(actions, index, verbose=not args.quiet)
  File "C:\Anaconda2\lib\site-packages\conda\plan.py", line 538, in execute_acti
ons
    inst.execute_instructions(plan, index, verbose)
  File "C:\Anaconda2\lib\site-packages\conda\instructions.py", line 148, in exec
ute_instructions
    cmd(state, arg)
  File "C:\Anaconda2\lib\site-packages\conda\instructions.py", line 95, in UNLIN
K_CMD
    install.unlink(state['prefix'], arg)
  File "C:\Anaconda2\lib\site-packages\conda\install.py", line 714, in unlink
    os.unlink(meta_path)
WindowsError: [Error 5] Access is denied: 'C:\\Anaconda2\\conda-meta\\conda-3.19
.1-py27_0.json'

[Anaconda2] C:\Users\User>

尝试以管理员身份运行 Anaconda 提示符:

在此处输入图像描述

于 2015-10-11T17:30:14.943 回答