简体   繁体   中英

Python + cx_Oracle : Unable to acquire Oracle environment handle

Background .
My OS is Win7 64bit.
My Python is 2.7 64bit from python-2.7.8.amd64.msi
My cx_Oracle is 5.0 64bit from cx_Oracle-5.0.4-10g-unicode.win-amd64-py2.7.msi
My Oracle client is 10.1 (I don't know 32 or 64 arch, but SQL*Plus is 10.1.0.2.0

Database is
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

ORACLE_HOME variable added from haki reply.
C:\\Oracle\\product\\10.1.0\\Client_1\\

Not work problem still persist.

ORACLE_HOME Try Oracle instant from instantclient-basic-win64-10.2.0.5.zip C:\\instantclient_10_2\\

C:\\Users\\PavilionG4>sqlplus Lee/123@chstchmp
Error 6 initializing SQL*Plus
Message file sp1.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

My sql*plus is not let me set the Oracle.

ORACLE_HOME Come back to the
C:\\Oracle\\product\\10.1.0\\Client_1\\

PATH variable
C:\\Program Files (x86)\\Seagate Software\\NOTES\\
C:\\Program Files (x86)\\Seagate Software\\NOTES\\DATA\\
C:\\Program Files (x86)\\Java\\jdk1.7.0_05\\bin
C:\\Oracle\\product\\10.1.0\\Client_1\\bin
C:\\Oracle\\product\\10.1.0\\Client_1\\jre\\1.4.2\\bin\\client
C:\\Oracle\\product\\10.1.0\\Client_1\\jre\\1.4.2\\bin
C:\\app\\PavilionG4\\product\\11.2.0\\dbhome_1\\bin
C:\\app\\PavilionG4\\product\\11.2.0\\client_2\\bin
c:\\Program Files (x86)\\AMD APP\\bin\\x86_64
c:\\Program Files (x86)\\AMD APP\\bin\\x86
C:\\Windows\\system32
C:\\Windows
C:\\Windows\\System32\\Wbem
C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\
c:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static
C:\\Users\\PavilionG4\\AppData\\Local\\Smartbar\\Application\\
C:\\PROGRA~2\\IBM\\SQLLIB\\BIN
C:\\PROGRA~2\\IBM\\SQLLIB\\FUNCTION
C:\\Program Files\\gedit\\bin
C:\\Kivy-1.7.2-w32
C:\\Program Files (x86)\\ZBar\\binj
C:\\Program Files (x86)\\Java\\jdk1.7.0_05\\bin
C:\\Program Files\\MATLAB\\R2013a\\runtime\\win64
C:\\Program Files\\MATLAB\\R2013a\\bin
C:\\Python27

TNS is :
C:\\Oracle\\product\\10.1.0\\Client_1\\NETWORK\\ADMIN\\tnsnames.ora
REPORT1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.28.128.110)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = REPORT1)
)
)

f1.py shows me error
import cx_Oracle
ip = '172.25.25.42'
port = 1521
SID = 'REPORT1'
dns_tns = cx_Oracle.makedsn(ip,port,SID)
connection = cx_Oracle.connect(u"Lee",u"123",dns_tns)
cursor = connection.cursor() connection.close()

Error
Traceback (most recent call last):
File "f1.py", line 6, in
connection = cx_Oracle.connect(u"Lee",u"123",dns_tns)
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

Questions
1. How to acquire Oracle environment handle?
I had searched the websites. Unfortunately they are not hit my problem at all.
2. How to let Python use another Oracle client without impact to the existing one?

If python finds more than one OCI.DLL file in the path (even if they are identical) it will throw this error. (Your path statement looks like it may throw up more than one). You can manipulate the path inside your script to constrain where python will look for the supporting ORACLE files which may be your only option if you have to run several versions of oracle/clients locally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM