python通过cx_Oracle连接oracle设置

本文解决在Windows环境下使用Python的cx_Oracle模块连接Oracle数据库时遇到的DLL加载失败问题,通过重新下载Python版本、更换环境变量、安装正确版本的cx_Oracle并配置TNS_ADMIN路径,最终实现成功导入cx_Oracle并建立数据库连接。

Python的Oracle数据库包cx_Oracle。win7x64位,cx_Oracle-5.1.2-11g.win-amd64-py2.7。

进入Python的编辑环境

>>> import cx_Oracle

Traceback (most recent call last):

  File "<pyshell#1>", line 1, in <module>

    import cx_Oracle

ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。


重新下载Python 2.7.7的64位版,换掉环境变量,安装cx_Oracle-5.1.2-11g.win-amd64-py2.7,import  成功。

cx_Oracle是要调用OCI来联接Oracle数据库,11gx64 对应64python 和cx_Oracle。

Python下载 http://www.python.org/
cx_Oracle下载 http://cx-oracle.sourceforge.net/

http://sourceforge.net/projects/cx-oracle/files/5.1.2/


在环境变量中添加一个变量名字为TNS_ADMIN的变量,值为ora文件目录 

cxoracle

import cx_Oracle
con = cx_Oracle.connect("duser/pswd@db")
print con.version
con.close()



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值