gpt4 book ai didi

python - 在 Windows 中部署 cx_Oracle

转载 作者:可可西里 更新时间:2023-11-01 14:42:46 31 4
gpt4 key购买 nike

我正在尝试在 python 中使用 cx_Oracle 模块来访问远程数据库并插入或删除表中的行。顺便说一句,我已经下载了 oracle 即时客户端 11.1 以及 odbc 和 sqlplus 版本。我已将环境变量 ORACLE_HOMETNS_ADMIN 设置到目录,我在那里解压缩文件并将此目录添加到 PATH 变量。当我用谷歌搜索时,我认为应该有一些 .ora 文件,但我找不到它们。

我可以从命令行使用sqlplus 命令,但我的主要问题是我无法安装和使用cx_Oracle。我不想使用任何命令行脚本;我只想将 cx_Oracle 用作 API。

谁能给我一个完整的解释,我真的被困在那里了。这方面的所有文件都是模糊的。最好的问候。

编辑 1:

我用python setup.py installpython setup.py build --compiler=mingw32 命令尝试了cx_Oracle 的源码包。我没有再次收到 oracle 错误,但收到了 command 'gcc' failed 错误。我尝试了 MinGW 编译器并编辑了环境变量 PATH 以包含 MinGW 安装目录(例如 C:\MinGW);我还安装了 Microsoft Visual C++(版本 2005、2008 和 2010);但我仍然收到错误。

编辑 2:

自从 @jpmc26 提到了 tnsnames.ora 文件,我决定补充一点,我已经尝试制作一个 tnsnames.ora 和一个 sqlplus.ora 文件并将它们放在目录 C:\oracle\instant_client_11_1\network\admin 中;但是当我用谷歌搜索时,我意识到如果你使用 cx_Oracle.connect(username, password, cx_Oracle.makedsn(ip, port, sid)) 命令,你可以跳过 .ora文件。 cx_Oracle.makedsn 将生成结构本身。

最佳答案

我试了很多方法终于解决了这个问题。既然我觉得我应该写一个全面的答案,我就把我遇到的问题和解决方法分别写出来;希望它可以帮助别人。我还将问题的名称更改为适当的名称。这是我在 Windows 7 - 32 位版本中安装 cx_Oracle 模块时所经历的(我认为其他版本的 Windows 会有类似的解决方案,但我不确定):

  • 我已经尝试使用 easy_install 安装 cx_Oracle 并且我得到了错误 No oracle client installed。我下载了oraclebasic instant client 和 oracle sdk instant client for windows fromOracle官网,按照以下步骤安装:

    Unzip oracle basic instant client into directory C:\oracle\instant_client_11_1\.

    Unzip oracle sdk instant client and copy folder sdk into the directory C:\oracle\instant_client_11_1\, consequently we have a directory as C:\oracle\instant_client_11_1\sdk\.

    Add C:\oracle\instant_client_11_1\ to the end of the PATH environment variable.

    Add a new variable named ORACLE_HOME and set C:\oracle\instant_client_11_1\ for the value.

    Restart computer.

  • 我尝试再次使用 easy_install 安装 cx_Oracle,我得到了错误 command ‘gcc’ failed: no such file or directory 在某些情况下案例 无法找到 vcvarsall.bat;这是因为我没有一个 C++ 编译器,所以我按照以下步骤来解决它:

    Download Microsoft Visual C++ and install it.

    Download MinGW and install it; note that you must install GCC module.

    Add C:\MinGW\ and C:\MinGW\bin\(which contains gcc.exe) to the end of the PATH environment variable.

  • 我尝试再次使用 easy_install 安装 cx_Oracle,我得到了错误 command ‘gcc’ failed with exit status 1;我试过这一步解决它:

    Open file C:\Python27\Lib\distutils\ cygwincompiler.py and remove all –mno-cygwin occurrences in this file; this is because recent versions of GCC has removed –mno-cygwin option and it shouldn’t be there.

  • 我尝试使用 easy_install 安装 cx_Oracle,它成功了。

但是在网上搜索的过程中,我发现了一些可能有用的技巧:

  • 如果你得到错误no module named win32api,那是因为你没有你应该在你的电脑上安装 python 的 win32 扩展从 Source Forge 下载 pywin32 模块并安装它。

  • 如果你还是没有成功,你可以尝试旧版本的cx_Oracle;但请记住我们在以上几行中谈到的所有内容。您可以找到所有版本的 cx_Oracle here .

  • 如果您想使用 sqlplus,您还应该执行其他一些步骤。为此,请搜索互联网。

关于python - 在 Windows 中部署 cx_Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20472060/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com