帮助安装cx_Oracle
我正在尝试为Python 2.6安装cx_Oracle,但遇到了问题,安装失败。我对C语言或微软Visual 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 Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle Traceback (most recent call last): File "", line 1, in ImportError: DLL load failed: The specified module could not be found.
我猜这意味着它没有正确安装。如果有人能告诉我我哪里做错了,那也是一个很好的答案。
----------------------------- 编辑2 -----------------------------
我已经从Oracle的基本客户端下载了所有文件,版本是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
3 个回答
3
如果你使用的是 Anaconda 的 64 位 Python,那么事情会变得 简单一些:
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 提示符:
19
你为什么不使用像 Windows安装包(Oracle 10g,Python 2.6) 这样的二进制包呢?
可以查看 http://cx-oracle.sourceforge.net/ 来获取其他的二进制包。
补充说明(应要求提供):你必须确保使用的 cx_Oracle 满足以下条件:
- 如果没有这个环境变量,必须设置 ORACLE_HOME(可以查看这个 Oracle常见问题解答)
- Python 能找到
oraocci11.dll
(用于 Oracle 11g)、oraocci10.dll
(用于 Oracle 10g)或oraclient9.dll
(用于 Oracle 9i),你需要把 DLL 所在的文件夹(通常是 %ORACLE_HOME%/bin)添加到你的 PATH 环境变量中 - 使用正确的二进制包(也就是说,要为合适的 Python 和 Oracle 版本构建的包)