cx_Oracle连接数据库报DPI-1047: Cannot locate a 64-bit Oracle Client library

针对这个问题查了很多资料,大部分的说法是python版本、oracle客户端版本、操作系统都要是64位的。其实只需要pthon版本和oracle客户端版本一致即可,即都为64位或都为32位。

但我这里要讲的是如何解决这个问题的过程:

在python中的报错中提示了这个:

DPI-1047: Cannot locate a 64-bit Oracle Client library: "The specified module could not be found". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help

所以最靠谱的方法是去https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html 这里找资料。根据文档中的方法,我们可以看到这个:

 cx_Oracle.init_oracle_client() to set the Oracle Client directory:

import cx_Oracle
import sys
import os

try:
    if sys.platform.startswith("darwin"):
        lib_dir = os.path.join(os.environ.get("HOME"), "Downloads",
                               "instantclient_19_8")
        cx_Oracle.init_oracle_client(lib_dir=lib_dir)
    elif sys.platform.startswith("win32"):
        lib_dir=r"C:\oracle\instantclient_19_9"
        cx_Oracle.init_oracle_client(lib_dir=lib_dir)
except Exception as err:
    print("Whoops!")
    print(err);
    sys.exit(1);

使用这个的好处是:不用到处去设置变量让cx_Oracle去查找oracle client的路径。

我自己的情况,设置了这个之后,不会报DPI-1047错误了,但报了另一个:DPI-1072: the Oracle Client library version is unsupported, 这个问题查了很久,最后在这篇文中找到了答案: https://oracle.github.io/odpi/doc/installation

ODPI-C dynamically loads available Oracle Client libraries at runtime. This allows code using ODPI-C to be built only once, and then run using any available Oracle Client 21, 19, 18, 12, or 11.2 libraries. If Oracle Client libraries are not found, the error “DPI-1047: Cannot locate an Oracle Client library” is raised. If an Oracle Client library is found but the version cannot be determined, the error “DPI-1072: the Oracle Client library version is unsupported” is raised. For example, this could be because the Oracle Client library version is too old (prior to 10g) or entirely unsupported (such as Oracle Client 19 on Windows 7).

里面说win7 不支持 oracle client 19 。

后面换了18.5的版本,还不是行,干脆换成11.1版本了,换成了这个报错 :DPI-1050: Oracle Client library is at version 11.1 but version 11.2 or higher is needed

看到这个大喜过望, 直接换成了11.2版本,就可以了。

后面还报了另一个错:

sqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

这个是由于 python连接cx_oracle时,要用SERVICE_NAME,而不是sid,这个在你要连接的库中查询一下就好:

select value from v$parameter where name like '%service_name%';

然后替换一下这里标红的地方即可:

dsnstr=cx_Oracle.makedsn('172.xx.xx.xx','1521',service_name='sidxx')
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值