在 Windows 中部署 cx_Oracle [英] Deploying cx_Oracle in Windows
问题描述
我正在尝试在 python 中使用 cx_Oracle
模块来访问远程数据库并在表中插入或删除行.顺便说一句,我已经下载了 oracle 即时客户端 11.1 以及 odbc 和 sqlplus 版本.我已将环境变量 ORACLE_HOME
和 TNS_ADMIN
设置到目录中,我在那里解压缩了文件并将此目录添加到 PATH
变量中.当我用谷歌搜索时,我认为应该有一些 .ora
文件,但我找不到它们.
I'm trying to use cx_Oracle
module in python to access a remote database and insert or delete rows in tables. BTW I have downloaded oracle instant client 11.1 and also odbc and sqlplus versions. I have set environment variables ORACLE_HOME
and TNS_ADMIN
to directory I have unzipped files there and add this this directory to the PATH
variable. As I googled I think there should be some .ora
files but I can't find them.
我可以从命令行使用 sqlplus
命令,但我的主要问题是我无法安装和使用 cx_Oracle
.我不想使用任何命令行脚本;我只想使用 cx_Oracle
作为 API.
I can use sqlplus
commands from command line, but my main problem is that I can't install and use cx_Oracle
. I don't want to use any command line scripts; I just want to use cx_Oracle
as an API.
谁能给我一个完整的解释,我真的被困在那里.这方面的所有文件都含糊其辞.最好的问候.
Can anyone give me a complete explanation, I'm really stuck there. All the documents in this area are vague. Best Regards.
编辑 1:
我使用 python setup.py install
和 python setup.py build --compiler=mingw32
命令尝试了 cx_Oracle
的源包.我没有再收到 oracle 错误,但我收到 command 'gcc' failed
错误.我尝试了 MinGW 编译器并编辑了环境变量 PATH
以包含 MinGW 安装目录(例如 C:MinGW
);我还安装了 Microsoft Visual C++(版本 2005、2008 和 2010);但我仍然收到错误消息.
I tried the source package of cx_Oracle
with python setup.py install
and python setup.py build --compiler=mingw32
commands. I don't get the oracle error again, but I'm getting command 'gcc' failed
error. I tried MinGW compiler and have edited environment variable PATH
to contain MinGW install directory(e.g. C:MinGW
); I have also installed Microsoft Visual C++(versions 2005, 2008 and 2010); but I still get the error.
编辑 2:
由于@jpmc26 提到了 tnsnames.ora
文件,我决定补充一点,我已经尝试制作一个 tnsnames.ora
和一个 sqlplus.ora
文件并将它们放在 C:oracleinstant_client_11_1
etworkadmin
目录下;但当我用谷歌搜索时,我意识到如果你使用 cx_Oracle.connect(username, password, cx_Oracle.makedsn(ip, port, sid))
命令,你可以跳过 .ora
文件.cx_Oracle.makedsn
将自己制作结构.
Since @jpmc26 mentioned about tnsnames.ora
files, I decided to add that I have tried to make a tnsnames.ora
and also a sqlplus.ora
file and put them in directory C:oracleinstant_client_11_1
etworkadmin
; but as I googled I realized that if you use cx_Oracle.connect(username, password, cx_Oracle.makedsn(ip, port, sid))
command, you can skip .ora
files. cx_Oracle.makedsn
would make the structure itself.
推荐答案
我尝试了很多方法,最终解决了问题.既然觉得应该写一个全面的答案,就分别写下我遇到的问题和解决方法;希望它能帮助别人.我还将问题的名称更改为合适的名称.这是我在 Windows 7 - 32 位版本中安装 cx_Oracle
模块时所经历的(我认为其他版本的 Windows 会有类似的解决方案,但我不确定):
I tried a lot of ways to finally solve the problem. Since I think I should write a comprehensive answer, I will write the problems that I faced and their solutions respectively; hoping it can help others. I also changed the question's name to an appropriate one. Here's what I've been through during installation of cx_Oracle
module in Windows 7 - 32 bit version(I think other versions of windows would have similar solutions, but I'm not sure):
我尝试使用
easy_install
安装cx_Oracle
并且我得到了错误未安装oracle客户端
.我已经下载了oracle适用于 Windows 的基本即时客户端和 oracle sdk 即时客户端来自Oracle官网并通过以下步骤安装:
I have tried to install
cx_Oracle
usingeasy_install
and I got the errorNo oracle client installed
. I have downloaded oracle basic instant client and oracle sdk instant client for windows from Oracle Official Website and installed it via following steps:
将oracle基本即时客户端解压到目录C:oracleinstant_client_11_1
.
Unzip oracle basic instant client into directory
C:oracleinstant_client_11_1
.
解压oracle sdk即时客户端,将文件夹sdk
复制到C:oracleinstant_client_11_1
目录下,这样我们就有了C:oracle目录instant_client_11_1sdk
.
Unzip oracle sdk instant client and copy folder sdk
into the directory C:oracleinstant_client_11_1
, consequently we have a directory as C:oracleinstant_client_11_1sdk
.
将 C:oracleinstant_client_11_1
添加到 PATH
环境变量的末尾.
Add C:oracleinstant_client_11_1
to the end of the PATH
environment variable.
添加一个名为 ORACLE_HOME
的新变量,并将值设置为 C:oracleinstant_client_11_1
.
Add a new variable named ORACLE_HOME
and set C:oracleinstant_client_11_1
for the value.
重新启动计算机.
我尝试再次使用 easy_install
安装 cx_Oracle
并且我得到了错误 command ‘gcc’ failed: no such file or directory
和在某些案例无法找到vcvarsall.bat
;这是因为我没有一个 C++ 编译器,所以我按照以下步骤来解决它:
I tried to install cx_Oracle
using easy_install
again and I got
error command ‘gcc’ failed: no such file or directory
and in some
cases unable to find vcvarsall.bat
; this was because I didn’t have
a C++ compiler, so I followed these steps to solve it:
下载 Microsoft Visual C++ 并安装.
Download Microsoft Visual C++ and install it.
下载MinGW并安装;请注意,您必须安装 GCC 模块.
Download MinGW and install it; note that you must install GCC module.
添加 C:MinGW
和 C:MinGWin
(其中包含 gcc.exe
)到最后PATH
环境变量.
Add C:MinGW
and C:MinGWin
(which contains gcc.exe
) to the end of the PATH
environment variable.
我尝试再次使用 easy_install
安装 cx_Oracle
并且我得到了error command ‘gcc’ failed with exit status 1
;我试过这一步解决它:
I tried to install cx_Oracle
using easy_install
again and I got
error command ‘gcc’ failed with exit status 1
; I tried this step to
solve it:
打开文件 C:Python27Libdistutilscygwincompiler.py
并删除此文件中所有出现的 –mno-cygwin
;这是因为最近版本的 GCC
删除了 –mno-cygwin
选项,它不应该在那里.
Open file
C:Python27Libdistutils cygwincompiler.py
and remove all–mno-cygwin
occurrences in this file; this is because recent versions ofGCC
has removed–mno-cygwin
option and it shouldn’t be there.
我尝试使用 easy_install
安装 cx_Oracle
并且成功了.
I tried to install cx_Oracle
using easy_install
and it worked.
但在互联网上搜索时,我发现了一些可能有用的技巧:
But during searching in the internet I found a couple of tricks that may be useful:
如果你得到错误
no module named win32api
,那是因为你没有你应该在你的电脑上安装 python 的 win32 扩展从 Source Forge 下载pywin32
模块并安装它.
If you got error
no module named win32api
, it’s because you didn’t install win32 extensions of python on your computer you should downloadpywin32
module from Source Forge and install it.
如果还是没成功,可以试试旧版的cx_Oracle
;但请记住我们在上面几行中谈到的所有内容.您可以在 此处cx_Oracle>.
If you didn’t succeed anyway, you can try an older version of cx_Oracle
; but keep in mind all we talked about in the above lines. You can find all versions of cx_Oracle
here.
如果您想使用 sqlplus
,您还应该执行一些其他步骤.为此,请在互联网上搜索.
If you want to use sqlplus
you should do some other steps too. For this purpose search the internet.
这篇关于在 Windows 中部署 cx_Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!