本文介绍了cx_oracle和python 2.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python 2.7和cx_oracle(Windows x86 Installer(Oracle 10g,Python 2.7))和'm来不及设置以下简单示例才能正常工作:

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()

错误消息:

Traceback (most recent call last):
  File "C:\ORACON.py", line 1, in <module>
    import cx_Oracle
ImportError: DLL load failed: The specified module could not be found.

现在,我所做的是:

1)安装了cx_oracle二进制文件;

1) installed the cx_oracle binary;

2)从oracle网站下载了Instantclient_10_2并将路径导出到环境;

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

有人知道我想念什么吗?

Anyone know what im missing?

感谢您的阅读时间。

推荐答案

我能够通过以下步骤解决此问题:

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


  1. 下载来自

将其解压缩到名为oraclient的c:\中。

unzipped the into my c:\ with the name oraclient

创建目录结构C: \oraclient\network\admin以添加TNSNAMES.ORA

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

添加了指向C:\oraclient\network\的TNS_ADMIN env var admin

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

添加了指向C:\oraclient\

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

$的ORACLE_HOME env var b
$ b

之后,我使用以下代码:

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.

这篇关于cx_oracle和python 2.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 12:29