python - cx_oracle 和 python 2.7

标签 python python-2.7 cx-oracle

<分区>

我使用的是 python 2.7 和 cx_oracle(Windows x86 安装程序(Oracle 10g,Python 2.7))并且我没有时间设置这个简单的例子来工作:

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 二进制文件;

2) 从oracle网站下载instantclient_10_2并导出环境路径;

有人知道我缺少什么吗?

感谢您花时间阅读本文。

最佳答案

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

  1. Oracle Website下载instantclient-basic-win32-10.2.0.5

  2. 将名称为 oraclient 的文件解压到我的 c:\

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

  4. 添加了指向 C:\oraclient\network\admin 的 TNS_ADMIN 环境变量

  5. 添加了指向 C:\oraclient\的 ORACLE_HOME 环境变量

之后我使用了下面的代码:

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

希望对大家有帮助。

关于python - cx_oracle 和 python 2.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13708998/

相关文章:

python - 在 python admin sdk 中处理 Firebase 错误

用于播放固定频率声音的 Python 库

python - 是否可以对 argparse 参数执行 2 个操作?

屏幕窗口中的 Python 脚本,cx_oracle 错误

python - 为什么单层感知器在没有归一化的情况下收敛如此之慢,即使边距很大?

python - 使用 pandas 的交叉表时出现 ValueError

python - 检查所有位是否为 1 的最佳方法是什么?

python - 在 Python 中使用 '@patch.object' 和 'with patch.object' 有什么区别?

python - cx_Oracle中如何使用Pandas Write_Frame将结果导出到Oracle数据库

python - cx_Oracle 未安装在 Oracle Linux 上