简体   繁体   English

Anaconda 3.5(64位Windows)安装cx_Oracle

[英]Anaconda 3.5 (64bit Windows) Install cx_Oracle

I have installed Anaconda 3.5 for Windows 64bits, and I need to connect to the Oracle database using package "cx_Oracle". 我已经为Windows 64位安装了Anaconda 3.5,并且需要使用“ cx_Oracle”软件包连接到Oracle数据库。

I tried with the anaconda way: 我尝试了蟒蛇的方式:

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

The error messages below: 以下错误消息:

Hint: the following packages conflict with each other:
  - cx_oracle
  - python 3.5*
Use 'conda info cx_oracle' etc. to see the dependencies for each package.
Note that the following features are enabled:
  - vc14

It seems that cx_oracle isn't compatible with Python 3.5. 看来cx_oracle与Python 3.5不兼容。

After this, I also tried to install directly with the binary: 之后,我还尝试直接使用二进制文件进行安装:

python setup.py install

It throws a bunch of errors like: 它引发了很多错误,例如:

cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobGetChunkSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtExecute
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileClose

Is there a way to install cx_oracle for Anaconda 3.5 ?? 有没有一种方法可以为Anaconda 3.5安装cx_oracle?

It's kind of non-trivial. 这是不平凡的。 However doable. 但是可行。 Follow these steps: 跟着这些步骤:

1) Download Oracle Instant client for Windows x64 from 1)从Windows下载适用于Windows x64的Oracle Instant Client

http://www.oracle.com/technetwork/topics/winx64soft-089540.html http://www.oracle.com/technetwork/topics/winx64soft-089540.html

eg choose client eg 11.2.0.4 例如选择客户,例如11.2.0.4

-> instantclient-basic-windows.x64-11.2.0.4.0.zip -> Instantclient-basic-windows.x64-11.2.0.4.0.zip

-> instantclient-sdk-windows.x64-12.1.0.2.0.zip -> Instantclient-sdk-windows.x64-12.1.0.2.0.zip

2) Create directory and unzip the client & sdk in there: 2)创建目录并在其中解压缩客户端和SDK:

eg c:\\ora\\11gx64 例如c:\\ ora \\ 11gx64

3) Set ORACLE_HOME and TNS_ADMIN 3)设置ORACLE_HOME和TNS_ADMIN

See https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10 for details 有关详细信息,请参见https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10

eg ORACLE_HOME=c:\\ora\\11gx64 例如ORACLE_HOME = c:\\ ora \\ 11gx64

and TNS_ADMIN=c:\\ora\\11gx64 TNS_ADMIN = c:\\ ora \\ 11gx64

also add %ORACLE_HOME% in Your %PATH% 还要在您的%PATH%中添加%ORACLE_HOME%

4) In the created directory put file tnsnames.ora and fill with connection string to db: 4)在创建的目录中放入文件tnsnames.ora并用连接字符串填充到db:

%ORACLE_HOME%**tnsnames.ora** %ORACLE_HOME%** tnsnames.ora **

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

-> replace 127.0.0.1 with your hostname ->用您的主机名替换127.0.0.1

-> replace XE with your SID ->用您的SID替换XE

5) I suppose You've got already Python installed. 5)我想您已经安装了Python。

-> Otherwise visit Download page for Python ->否则,请访问Python的下载页面

-> Install python (3.6.1 in the time of writting) ->安装python(撰写本文时为3.6.1)

-> If not installed install pip ( https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip ) ->如果未安装,请安装pip( https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip

-> execute python get-pip.py ->执行python get-pip.py

6) Download and Install Visual C++ 2015 Build Tools 6)下载并安装Visual C ++ 2015生成工具

-> Search for Visual C++ 2015 Build Tools -> Install visualcppbuildtools_full.exe ->搜索Visual C ++ 2015生成工具->安装visualcppbuildtools_full.exe

7) Use pip to install cx_oracle 7)使用pip安装cx_oracle

  pip install cx_oracle

(in the time of writing there is trouble with default installed version 5.3 so the Version 6.0b2 has to be installed) (在撰写本文时,默认安装的版本5.3有问题,因此必须安装版本6.0b2)

  python -m pip install cx_Oracle --pre

The first steps are universal in my honest opinion for both conda and pip. 我诚实地认为,对于conda和pip来说,第一步是普遍的。

I couldn't install cx_oracle from pip3 or conda either. 我也无法从pip3或conda安装cx_oracle。 Got it working eventually by downloading the installer for windows 64 from pypi https://pypi.python.org/pypi/cx_Oracle/ 通过从pypi https://pypi.python.org/pypi/cx_Oracle/下载适用于Windows 64的安装程序,最终使其能够正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM