在Windows中安装Python cx_Oracle模块并连接到Oracle数据库 [英] Installing the Python cx_Oracle module in Windows and connecting to an Oracle database

查看:188
本文介绍了在Windows中安装Python cx_Oracle模块并连接到Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试安装和设置它,尽管有几个链接描述了如何执行此操作,但我只是没有使它起作用.我将首先描述设置:

I've been trying to get this installed and setup, and despite there been several links describing how to do this, I'm just not getting this to work. I'll describe first the setup:

  • 我的电脑:Windows 8.1 Enterprise(62位)
  • 远程服务器:Oracle DB版本12.1.0.2
  • C:\Users\Pymat\Oracle\instantclient_12_1 这是oraocci12.dll以及其他文件夹和文件的位置
  • C:\Users\Pymat\AppData\Local\Continuum\Anaconda3 这是python.exe所在的位置(即os.path.dirname(sys.executable)) 在脚本中,我有print (sys.version),它给出了: 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]
  • My PC: Windows 8.1 Enterprise (62 Bit)
  • Remote Server: Oracle DB Version 12.1.0.2
  • C:\Users\Pymat\Oracle\instantclient_12_1 Here is where oraocci12.dll is located, as well as other folders and files
  • C:\Users\Pymat\AppData\Local\Continuum\Anaconda3 Here is where the python.exe is located (i.e. os.path.dirname(sys.executable)) In a script, I have print (sys.version) which gives: 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]

我一直在参考此处此处此处.

I have been referring to instructions from here and here and here and here and here.

问题1:哪个是cx_Oracle的正确下载? 我从此处转到了cx_Oracle 5.2.1. 并下载:

Question 1: Which is the correct download for cx_Oracle? I went to cx_Oracle 5.2.1 from here and downloaded:

cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe (md5)
cx_Oracle-5.2.1-12c.win32-py3.5.exe (md5)

尚不清楚其中哪个是正确的.exe要下载(或也许两者都是正确的).无论如何,我似乎都使用12c来使版本与Oracle DB版本保持一致,尽管在整个过程中,无论如何在任何情况下似乎都不会与远程服务器上的Oracle DB进行交互.

It's not clear which of these is the correct .exe to download (or maybe both is correct). In any case, I use 12c to keep the versions consistent with the Oracle DB Version, although through this entire process there is no interaction with the Oracle DB on the remote server in any case, it seems.

问题2: cx_Oracle是否已正确下载或丢失?

Question 2: Is cx_Oracle correctly downloaded or actually missing?

在以下路径下:

C:\Users\Pymat\AppData\Local\Continuum\Anaconda3\Lib\site-packages

我发现:

cx_Oracle.cp35-win_amd64.pyd
cx_Oracle.cp35-win32.pyd

但是,根据

However I don't find under this directory (or any other) the cx_Oracle, like for example Verion-5.1.2-11g.win32-py2.7, as per here. I suspect there is an issue with locating the cx_Oracle module. See also Question 5

问题3:我的环境变量配置正确吗?

Question 3: Are my environment variables configured correctly?

(i)当我在Windows中使用GUI来检查变量时,例如此处我看到了:

(i) When I use the GUI in Windows to check the variables like here I see:

ORACLE_HOME
C:\Users\Pymat\Oracle\instantclient_12_1;
C:\Users\Pymat\Oracle\instantclient_12_1\vc12

PATH
C:\Users\Pymat\AppData\Local\Continuum\Anaconda3;
C:\Users\Pymat\AppData\Local\Continuum\Anaconda3\Scripts;
C:\Users\Pymat\AppData\Local\Continuum\Anaconda3\Library\bin;
C:\Users\Pymat\Oracle\instantclient_12_1;

NB: ORACLE_HOME的末尾缺少分号.正确吗?

NB: The semi-colon is missing at the end of ORACLE_HOME. Is that correct?

(ii)当我在Command中使用C:\Users\Pymat>echo %PATH%时:

(ii) When I use C:\Users\Pymat>echo %PATH% in Command:

C:\ProgramData\Oracle\Java\javapath;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Users\Pymat\.dnx\bin;
C:\Program Files\Microsoft DNX\Dnvm\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\Users\Pymat\AppData\Local\Continuum\Anaconda3;
C:\Users\Pymat\AppData\Local\Continuum\Anaconda3\Scripts;
C:\Users\Pymat\AppData\Local\Continuum\Anaconda3\Library\bin;
C:\Users\Pymat\Oracle\instantclient_12_1;

(iii)当我进入Python外壳并使用sys.path时:

(iii) When I go into the Python shell and use sys.path:

'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\python36.zip', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\DLLs', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\lib', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\Sphinx-1.5.1-py3.6.egg', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\win32', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\win32\\lib', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\Pythonwin', 
'C:\\Users\\Pymat\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg'

问题4:即时客户端下载,哪些下载实际上是必不可少的?

Question 4: Instant Client Downloads, which downloads are actually essential?

在Oracle上注册后,我从此处下载12.1.0.2 即时客户端软件包-基本" 即时客户端软件包-SDK" .有些网站没有提到SDK程序包,但是我还是下载了它.

After registering on Oracle, I download from here under Version 12.1.0.2 the "Instant Client Package - Basic" and "Instant Client Package - SDK". Some sites don't mention the SDK package, but I downloaded it anyway.

这些已下载到我的PC(而不是Oracle DB所在的计算机)上.

These are downloaded to my PC (not where the Oracle DB resides).

问题5:为了测试安装是否成功,我进入了Python shell并使用:

Question 5: In order to test for a successful installation, I go into the Python shell and use:

import os
os.chdir("C:\\Users\\Pymat\\Oracle\\instantclient_12_1")
import cx_Oracle

但是我得到:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cx_Oracle'

为什么此步骤不起作用?

Why is this step not working?

问题6:我无法在Eclipse中正确使用Console,但是Command中的Python shell可以正常工作,为什么?

Question 6: I cannot use Console correctly in Eclipse, but the Python shell in Command works, why?

当我单击"PyDev控制台" ,然后单击""Python控制台" 时,我得到:

When I click on "PyDev Console", then "Python Console", I then get:

'Create Interactive Console' has encountered a problem
Error initializing console


这变得有点令人头疼,尽管我仍然是Python新手,但我认为此安装过程可能会容易得多.欢迎任何建议.


This is becoming a bit of a headache, and although I'm still a Python novice, I think this installation process could be a lot easier. Any advice welcome.

推荐答案

长话短说:现在降级到Python 3.5,将在下一个cx_Oracle版本中构建Python 3.6的二进制文件.

Long story short: Downgrade to Python 3.5 for now, binaries for Python 3.6 will be built with the next cx_Oracle release.

>


长版:

Long version:

在脚本中,我有print (sys.version),它给出了:3.6.0 [...]

我发现:

cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe (md5)
cx_Oracle-5.2.1-12c.win32-py3.5.exe (md5)

这些安装程序适用于Python 3.5(请参见py3.5).二进制Python模块在主要的Python版本之间不一定是API兼容的,这就是它们的文件名是特定于版本的原因.

These installers are for Python 3.5 (see py3.5 in their name). Binary Python modules aren't necessarily API-compatible between major Python releases, that's why their filenames are version-specific.

尚无适用于Windows的Python 3.6官方cx_Oracle二进制文件.一旦发布 cx_Oracle 5.3,它还将包括适用于Python 3.6的Windows安装程序(问题45).

There are no official cx_Oracle binaries for Windows for Python 3.6 yet. Once cx_Oracle 5.3 is released, it will include Windows installers for Python 3.6 as well (issue #45).

不会是官方的Python当前cx_Oracle版本5.2.1的3.6安装程序(请参阅问题#50).

同时,根据邮件列表中的Jani Tiainen,,它不应该自己构建二进制文件很困难-但我从来没有尝试过这样做:

Meanwhile, according to Jani Tiainen from the mailing lists, it shouldn't be difficult to build the binaries yourself -- but I've never tried this myself:

我认为您只需要从Microsoft下载Visual C ++ 14(2015) [1]和来自Oracle [2]的Instant Client库.那你应该能够 自己编译.

I think you only need to download Visual C++ 14 (2015) from Microsoft [1] and Instant Client libs from Oracle [2]. Then you should be able to compile it yourself.

请注意,Instant Client也需要SDK库.

Note that you need also SDK libs as well for Instant Client.

[1] http://landinghub.visualstudio.com/visual-cpp-构建工具

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

这篇关于在Windows中安装Python cx_Oracle模块并连接到Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆