It took another morning to configure this item and write it to reduce your detours. My environment is WINXP SP2 + python2.4 + Oracle 8i.
[1] first download the driver: (cx_oracle)
Http://www.python.net/crew/atuining/cx_Oracle/
But pay attention to the version and select it based on your situation.
[2] installation:
Run the EXE installer and copy a cx_oracle.pyd to the {python_home} \ Lib \ Site-packages directory.
[3] run a test program:
Import cx_oracle
Con = cx_oracle.connect ("xjtu_test", "37343734", "xjtu. World ")
Cursor = con. cursor ()
Cursor. Close ()
Con. Close ()
The three parameters in connect are user, pass, and TNS from left to right.
The TNS can be configured using the net configuration Assistant in the Oracle client tool.
[4] for specific cx_oracle APIs, refer:
Http://www.python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html
Okay. You must have encountered a problem when executing the test code. The following problems may occur:
[1] OCI. dll cannot be found in the report when you import cx_oracle:
Find one on the machine with Oracle installed, and copy it to the {python_home} \ Lib \ Site-packages directory.
[2] runtimeerror: unable to acquire Oracle environment handle reported during cx_oracle.connect:
This is troublesome and can be solved by following the steps below: (all steps may not be required. I did not confirm it, but I have executed all the steps below and solved the problem)
First, make sure that you are running the Python script under the console. Instead of some ides, such as pydev (they do not seem to be able to load OS environment variables ).
In fact, install oracle on the local machine (only the client tool can be installed ).
Finally, add the following environment variables: (I will give my environment variables and change them to your own path)
ORACLE_HOME = D: \ oracle \ ora81
Path = D: \ oracle \ ora81 \ bin; {your_other_paths}
I 've been stuck in pydev for a long time, FT ~, Then switch to the console and everything will be fine ,:-)