无法使用 Python cx_Oracle 设置与 Oracle DB 的连接

问题描述 投票:0回答:1

我正在使用 M1 Mac 通过 Python 3 中的 cx_Oracle 连接到 Oracle DB。

import cx_Oracle
import os
import platform

dsn_tns = cx_Oracle.makedsn('host', 'port', service_name='tns_service_name')
conn = cx_Oracle.connect(user='user', password='pwd', dsn=dsn_tns)
cx_Oracle.init_oracle_client(lib_dir='/Users/user/Downloads/instantclient_19_8')

我已按照here的说明安装了oracle客户端,但仍然无法连接并给出以下错误。

数据库错误:DPI-1047:无法找到 64 位 Oracle 客户端库: “dlopen(libclntsh.dylib,0x0001):尝试过:'libclntsh.dylib'(没有这样的 文件),'/usr/lib/libclntsh.dylib'(没有这样的文件), '/Users/balikuma/Desktop/libclntsh.dylib'(没有这样的文件)”。请参阅 https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html 寻求帮助

python python-3.x oracle apple-m1 cx-oracle
1个回答
0
投票

为了避免在 Apple M1 芯片上的 Python 中出现错误 DPI-1047,您可以升级 cx_Oracle。最新的主要版本(取代 cx_Oracle 8.3)有一个新名称python-oracledb。默认情况下,这个新版本不需要 Oracle 客户端库。检查安装文档

还有适用于 macOS x86 和 M1 的通用二进制包,因此您无需编译驱动程序或使用 Rosetta。 macOS 上存在适用于 Python 3.8、3.9 和 3.10 的软件包。

© www.soinside.com 2019 - 2024. All rights reserved.