[其实,cx_Oracle python module本身没啥多说的。我重点说一下在redhat上做cx_Oracle环境准备。安装Oracle Client我在oracle官网下载了oracle-instantclient11.2-basic-11.windows下使用python连接oracle(10.2.0)
从
http://cx-oracle.sourceforge.net/下载Windows x86 Installer (Oracle10g, Python 2.5)
安装以后 在python命令行中import cx_Oracle,报错误:python.exe - 无法找到入口, 无法定位程序输入点 OCIClientVersion 于动态链接库 OCI.dll 上。
原因:本机安装的windows客户端版本不对
解决方法:卸载本机的oracle9i客户端精简版,装oracle10i数据库软件,[import cx_Oracle >>> conn = cx_Oracle.connect('user','0909',cx_Oracle.makedsn('192.168.1.176',1521,'testDate')) >>> cur = conn.cursor() >>> cur.execute('select执行成功
>>> import cx_Oracle
>>> cx_Oracle.connect( "user", "pwd","database")
用py2exe把程序打包后放到运行环境上,出现错误:unable to acquire oracle environment handle
原因:运行环境和开发环境oracle客户端环境不一致
解决方法:运行环境装和开发环境相同的oracle客户端环境,运行环境也装oracle10i数据库软件
运行环境的oracle的客户端版本9?10?11?必须与使用的cx_Oracle对应的oracle版本一致
也可以在py2exe打包时,排除oci.dll,然后使用生产环境对应自己的oci.dll文件(通在生产环境的机器上设置环境变量:ORACLE_HOME为E:\oracle\product\10.2.0\db_1来实现),排除的代码如下:
setup(
options = {'py2exe': {
'dll_excludes': ["oci.dll"]
}},
console=["study.py"],
)[From: http://space.itpub.net/22664653/viewspace-711728Python 连接Oracle数据库,需要使用cx_Oracle 包。1 下载cx_Oracle该包的下载地址:http://cx-oracle.sourceforg