python cx_oracle底层是什么,cx_oracle和python 2.7

Im using python 2.7 and cx_oracle ( Windows x86 Installer (Oracle 10g, Python 2.7) ) and 'm having a bad time to set this simple example bellow to work:

import cx_Oracle

connection = cx_Oracle.connect('user/pass@someserver:port')

cursor = connection.cursor()

cursor.execute('select sysdate from dual')

for row in cursor:

print row

connection.close()

Error Message:

Traceback (most recent call last):

File "C:\ORACON.py", line 1, in

import cx_Oracle

ImportError: DLL load failed: The specified module could not be found.

For now, what i have done was:

1) installed the cx_oracle binary;

2) downloaded instantclient_10_2 from oracle website and exported the path to environment;

Anyone know what im missing?

Thank you for your time on reading this.

解决方案

I was able to solve this problem with the following steps:

Download instantclient-basic-win32-10.2.0.5 from Oracle Website

unzipped the into my c:\ with the name oraclient

Created the directory structure C:\oraclient\network\admin to add the TNSNAMES.ORA

Added the TNS_ADMIN env var pointing to C:\oraclient\network\admin

Added the ORACLE_HOME env var pointing to C:\oraclient\

After that i used the following code:

import cx_Oracle

con = cx_Oracle.connect('theuser', 'thepass', 'your DB alias on your TNSNAMES.ORA file ')

cur = con.cursor()

if cur.execute('select * from dual'):

print "finally, it works!!!"

else:

print "facepalm"

con.close()

I hope it helps someone.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值