cx_oracle和python 2.7

tcp*_*008 7 python cx-oracle python-2.7

我正在使用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()
Run Code Online (Sandbox Code Playgroud)

错误信息:

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.
Run Code Online (Sandbox Code Playgroud)

现在,我所做的是:

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

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

谁知道我失踪了什么?

感谢您抽出宝贵时间阅读本文.

tcp*_*008 21

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

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

  2. 解压缩到我的c:\中,名称为oraclient

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

  4. 添加了指向C:\ oraclient \network\admin的TNS_ADMIN env var

  5. 添加了指向C:\ oraclient \的ORACLE_HOME env var

之后我使用了以下代码:

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()
Run Code Online (Sandbox Code Playgroud)

我希望它对某人有帮助.

  • 使用`cx_Oracle.connect('theuser','thepass',cx_Oracle.makedsn('host',port,SID))`你可以避免步骤3,4和5. (12认同)