cx_oracle 和 python 2.7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13708998/
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-08-18 09:25:56  来源:igfitidea点击:

cx_oracle and python 2.7

pythonpython-2.7cx-oracle

提问by thclpr

Im using python 2.7 and cx_oracle ( Windows x86 Installer (Oracle 10g, Python 2.7) ) and 'm having a bad time to set this simple example bellow to work:

我正在使用 python 2.7 和 cx_oracle(Windows x86 安装程序(Oracle 10g,Python 2.7)),并且很难设置下面这个简单的示例来工作:

import cx_Oracle
connection = cx_Oracle.connect('user/pass@someserver:port')
cursor = connection.cursor()
cursor.execute('select sysdate from dual')

for row in cursor:
    print row
connection.close()

Error Message:

错误信息:

Traceback (most recent call last):
  File "C:\ORACON.py", line 1, in <module>
    import cx_Oracle
ImportError: DLL load failed: The specified module could not be found.

For now, what i have done was:

现在,我所做的是:

1) installed the cx_oracle binary;

1) 安装了 cx_oracle 二进制文件;

2) downloaded instantclient_10_2 from oracle website and exported the path to environment;

2)从oracle官网下载instantclient_10_2并导出环境路径;

Anyone know what im missing?

有谁知道我错过了什么?

Thank you for your time on reading this.

感谢您花时间阅读本文。

采纳答案by thclpr

I was able to solve this problem with the following steps:

我能够通过以下步骤解决这个问题:

  1. Download instantclient-basic-win32-10.2.0.5from Oracle Website

  2. unzipped the into my c:\ with the name oraclient

  3. Created the directory structure C:\oraclient\network\admin to add the TNSNAMES.ORA

  4. Added the TNS_ADMIN env var pointing to C:\oraclient\network\admin

  5. Added the ORACLE_HOME env var pointing to C:\oraclient\

  1. Oracle 网站下载instantclient-basic-win32-10.2.0.5

  2. 使用名称 oraclient 将其解压缩到我的 c:\

  3. 创建目录结构 C:\oraclient\network\admin 添加 TNSNAMES.ORA

  4. 添加了指向 C:\oraclient\network\admin 的 TNS_ADMIN 环境变量

  5. 添加了指向 C:\oraclient\ 的 ORACLE_HOME 环境变量

After that i used the following code:

之后我使用了以下代码:

import cx_Oracle

con = cx_Oracle.connect('theuser', 'thepass', 'your DB alias on your TNSNAMES.ORA file ')
cur = con.cursor()
if cur.execute('select * from dual'):
    print "finally, it works!!!"
else:
    print "facepalm"
con.close()

I hope it helps someone.

我希望它可以帮助某人。

回答by Kashyap

See this answer: https://stackoverflow.com/a/19552263/496289

看到这个答案:https: //stackoverflow.com/a/19552263/496289

ignore this.... making up other 17 bytes that're needed...

忽略这一点.... 弥补所需的其他 17 个字节...