2016-04-28 122 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文件。理論上他們會做同樣的事情。但從理論上說,一天之內不會讓我感覺到環境的建立。