【问题标题】:cx_Oracle connection fails with 'DPI-1047: Cannot locate a 64-bit Oracle Client library'cx_Oracle 连接失败并显示“DPI-1047:找不到 64 位 Oracle 客户端库”
【发布时间】:2020-11-23 20:28:26
【问题描述】:

使用连接 oracle 到 python 源的问题,oracle 现在可以用于其他语言 php (oci)

错误:

Traceback (most recent call last):
  File "c:\xampp\htdocs\pyoracle\testConnectionOracle.py", line 4, in <module>
    conn = cx_Oracle.connect('xxx','xxx', dsn_tns,'UTF-8')
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "failed to get message for Windows Error 126". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help

代码:

import cx_Oracle

dsn_tns = cx_Oracle.makedsn('192.168.1.217', '1521', service_name='xx') 
conn = cx_Oracle.connect('xx','xx', dsn_tns,'UTF-8')

c = conn.cursor()
c.execute('select * from database.table')
for row in c:
    print (row[0], '-', row[1])
conn.close()

【问题讨论】:

  • ORACLE_HOME 设置在您的PATH 中吗?
  • 如果正在使用 Oracle Instant Client,那么您不会(也不应该)设置 ORACLE_HOME。

标签: python windows oracle cx-oracle


【解决方案1】:

这里是cx_Oracle Windows installation instructions,您可能从您引用的错误消息中找到。

我假设 (i) 您实际上拥有 11g 或更高版本的 64 位 Oracle 客户端库,并且 (ii) 具有安装说明中提到的所需的 VS Redistributable。然后尝试一个简单的方法是将其添加到脚本的顶部:

cx_Oracle.init_oracle_client(lib_dir=r"C:\oracle\instantclient_19_6")

使用客户端库的实际路径。

PHP 可能是 32 位并使用 32 位 Oracle 库。如果是这样,因为您有 64 位 Python,那么您将需要安装 64 位 Instant Client 或安装 32 位 Python。 (注意 PHP OCI8 没有对 init_oracle_client() 的等效调用。在 PHP 中,您需要确保 Oracle 客户端库位于系统搜索路径中,例如 PHP 进程开始之前的 PATH。)

【讨论】:

    猜你喜欢
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    相关资源
    最近更新 更多