如何在不安装 Oracle 客户端和 cx_Oracle 的情况下访问 Oracle 数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19142677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:58:14  来源:igfitidea点击:

How do I access an Oracle db without installing Oracle's client and cx_Oracle?

pythonoraclepython-2.6cx-oracle

提问by Gary

I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access.

我有两个分别运行 Python 2.4 和 2.6 的 RHEL 服务器。我需要访问的另一台服务器上有一个 Oracle 数据库。

I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first.

我试图在我的 RHEL 服务器上安装 cx_oracle,但发现必须先安装 Oracle 客户端。

The problem is, I don't have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using:

问题是,我无权在两台 RHEL 服务器上安装 Oracle 的客户端。在相同的服务器上,Perl 程序可以使用以下命令连接到 Oracle 数据库:

DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password')

Can Python do the same without installing cx_oracle and the Oracle client? Or are there any suggestions about how to write a module myself to do the same thing?

Python 可以在不安装 cx_oracle 和 Oracle 客户端的情况下做同样的事情吗?或者对如何自己编写模块来做同样的事情有什么建议吗?

Thanks in advance!

提前致谢!

采纳答案by user632657

Usually, all you need are the libraries, which don't necessarily require sudo rights. Extract them to a place the software will be able to read from and set the following environment variables accordingly:

通常,您需要的只是库,它们不一定需要 sudo 权限。将它们提取到软件可以读取的位置,并相应地设置以下环境变量:

ORACLE_HOME=path/to/where/you/extracted/libs
TNS_ADMIN=path/to/tnsnames.ora

I have had best luck skipping tnsnames, and just specifying the host, port, etc in the connection, but it's quite possible you'll need it for cx_oracle...I don't remember from when I used it ages ago.

我很幸运地跳过了 tnsnames,只是在连接中指定了主机、端口等,但很可能你需要它来用于 cx_oracle......我不记得我很久以前是什么时候使用它的了。

回答by Erik Kaplun

An excerpt from https://forum.omz-software.com/topic/184/oracle-database:

摘自https://forum.omz-software.com/topic/184/oracle-database

There's no pure python client for Oracle and likely never will be. Even wonderful third-party toolsets like SQLalchemy still rely on cx_Oracle underneath to do the actual communication to the Oracle database servers.

Oracle 没有纯 python 客户端,而且可能永远不会。即使像 SQLalchemy 这样出色的第三方工具集仍然依赖于底层的 cx_Oracle 来与 Oracle 数据库服务器进行实际通信。

—also, deciding by Google, the answer is no: there do not seem to be any pure Python Oracle clients in existence as of today.

——此外,由 Google 决定,答案是否定的:截至今天,似乎没有任何纯 Python Oracle 客户端存在。

回答by FariZ

if you don't want use cx_Oracleyou should use expect scripting. ( for python pexpect). But you need to be carefully for handle all expectations.

如果您不想使用cx_Oracle,则应使用 expect 脚本。(对于python pexpect)。但是你需要小心处理所有的期望。