7

我正在使用 python 2.7 和 cx_oracle ( Windows x86 Installer (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()

错误信息:

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.

现在,我所做的是:

1) 安装 cx_oracle 二进制文件;

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

有谁知道我错过了什么?

感谢您花时间阅读本文。

4

1 回答 1

22

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

  1. Download instantclient-basic-win32-10.2.0.5 from 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\

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.

于 2012-12-10T13:00:30.447 回答