Mac运行node.js连接oracle数据库报DPI-1047: Cannot locate a 64-bit Oracle Client library: “dlopen(libclntsh.dy

本文档详细介绍了在遇到DPI-1047错误时,如何下载并安装Oracle 64位即时客户端以解决Node-oracledb连接失败的问题。步骤包括从指定网址下载BasicPackage,然后将文件复制到/usr/local/lib目录下,从而成功建立数据库连接。

错误信息:

DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/node-oracledb/INSTALL.html for help
Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
You must have the 64-bit Oracle Instant Client Basic or Basic Light package libraries in
/usr/local/lib or set by calling oracledb.initOracleClient({libDir: "/my/instant_client_directory"}).
Oracle Instant Client can be downloaded from http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
翻译:

DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh. dll) . "1):图像未找到"。参见https://oracle.github.io/node-oracledb/INSTALL.html寻求帮助
Node-oracledb安装说明:https://oracle.github.io/node-oracledb/INSTALL.html
您必须有64位Oracle即时客户端基本或基本轻包库
/usr/local/lib或通过调用oracledb设置。initOracleClient ({libDir:“/我/ instant_client_directory "})。
Oracle即时客户端可以从http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html下载

处理步骤如下:

1.点击http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html下载Basic Package(我下载的是instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg

2.下载完成双击 

3.把双击解压出来的东西拷贝到/usr/local/lib (访达>右键>前往文件夹)

OK,连接成功

### 问题分析 错误 `oracledb.exceptions.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library` 表明 Python 无法找到 Oracle 客户端库文件。这个问题通常出现在缺少 Oracle Instant Client 或者环境变量未正确配置的情况下。该问题在使用 `cx_Oracle` 或 `oracledb` 库时较为常见,尤其是在 Linux 或 Windows 系统上。 ### 解决方案 #### 1. 安装 Oracle Instant Client Oracle Instant Client 是一个轻量级的客户端库,用于连接 Oracle 数据库。根据操作系统选择对应的版本进行安装: - **Windows** 下载对应的 Oracle Instant Client Basic Package(64-bit)并解压到本地路径,例如 `C:\oracle\instantclient_21_10`。将该路径添加到系统环境变量 `PATH` 中,确保 Python 能够找到相关的 DLL 文件。 - **Linux** 下载 RPM 或 ZIP 格式的 Instant Client,并解压到 `/opt/oracle/instantclient_21_10`。设置环境变量: ```bash export ORACLE_HOME=/opt/oracle/instantclient_21_10 export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH ``` 或者使用 `ldconfig` 将库路径添加到系统中。 #### 2. 验证 Python 和 Oracle Instant Client 的位数一致性 确保 Python 和 Oracle Instant Client 的架构一致(均为 64 位或均为 32 位)。可通过以下命令查看 Python 的位数: ```python import platform print(platform.architecture()[0]) ``` 如果输出为 `64bit`,则需安装 64 位的 Oracle Instant Client[^1]。 #### 3. 使用 `cx_Oracle` 安装和配置 安装 `cx_Oracle` 并验证是否能正确加载 Oracle 客户端: ```bash pip install cx_Oracle ``` 测试连接: ```python import cx_Oracle try: connection = cx_Oracle.connect('username', 'password', 'hostname:port/servicename') cursor = connection.cursor() cursor.execute("SELECT * FROM dual") for row in cursor: print(row) cursor.close() connection.close() except cx_Oracle.DatabaseError as e: print(f"Database error: {e}") ``` #### 4. 使用 `oracledb` 替代方案 如果不想安装 Oracle Instant Client,可以考虑使用 `oracledb` 库,它支持“无客户端”模式(thin mode),无需额外安装 Oracle 客户端软件: ```bash pip install oracledb ``` 示例代码: ```python import oracledb try: connection = oracledb.connect(user='username', password='password', dsn='hostname:port/servicename') cursor = connection.cursor() cursor.execute("SELECT * FROM dual") for row in cursor: print(row) cursor.close() connection.close() except oracledb.DatabaseError as e: print(f"Database error: {e}") ``` #### 5. 内存不足问题处理(DPI-1001) 如果使用 `oracledb` 或 `cx_Oracle` 8.x 时遇到内存不足问题(`DPI-1001: out of memory`),可以尝试以下方法: - **减少批量插入的数据量**:将 `executemany` 的数据分批次提交,避免一次性加载过多数据。 - **优化内存使用**:确保每批数据处理完成后释放资源,关闭游标并提交事务。 - **升级库版本**:使用最新版本的 `oracledb`(如 1.2.1 或更高),以获得更好的内存管理和性能优化[^3]。 --- ###
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值