2016-04-28 121 views
0

我安装了python-2.7.amd64.msi和cx_Oracle-5.1.2-11g.win-amd64-py2.7.msi。Python无法在Windows 7上加载cx_Oracle

我使用PATH和PYTHONPATH环境变量探讨了很多,但没有任何帮助加载cx_Oracle模块。目前PYTHONPATH设置为 C:\ Python27 \ LIB \站点包

我非常基本的程序

import sys 
print sys.path 

import cx_Oracle 

conn_str = u'xxx/[email protected]/XXX' 
conn = cx_Oracle.connect(conn_str) 
c = conn.cursor() 
c.execute(u'select * from table') 
conn.close() 

程序输出是:

['C:\\Users\\terry\\IdeaProjects\\PythonScripts', 'C:\\Python27\\Lib\\site-packages', 'C:\\WINDOWS\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27'] 
Traceback (most recent call last): 
File "OracleTest.py", line 4, in <module> 
import cx_Oracle 
ImportError: DLL load failed: The specified module could not be found. 

我还添加注册表条目详细here

这在Linux上正常工作,所以它似乎我有问题的Windows安装程序。但我几乎用完了想法。

回答

0

这个问题(我认为)是我没有在Windows中设置ORACLE_HOME环境变量。这必须指向你的Oracle instantclient目录,例如ORACLE_HOME = C:\ instantclient_11_2

故事的“我认为”部分是,即使在设置后它没有帮助。我卸载了cx_Oracle并从头开始重新安装。这一次我也使用了python网站的cx_Oracle.EXE,而不是sourceforge的cx_Oracle.MSI文件。理论上他们会做同样的事情。但从理论上说,一天之内不会让我感觉到环境的建立。