Skip to main content
 首页 » 编程设计

python之使用 cx_oracle 连接到 Oracle 数据库在 Windows 上出现 DPI-1047

2025年01月19日898°冷暖

import pandas as pd 
import sqlalchemy 
 
engine = sqlalchemy.create_engine('oracle://XXX:XXX@XXX:XXX/?service_name=XXX') 
 
sql = 'select * from XXX where rownum < 10' 
df = pd.read_sql(sql,con=engine) 

DatabaseError: (cx_Oracle.DatabaseError) DPI-1047: 64-bit Oracle Client library cannot be loaded: "C:\oracle\11.2.0\bin\oci.dll is not the correct architecture". See https://oracle.github.io/odpi/doc/installation.html#windows for help

我正在尝试使用 Python 连接到 Oracle 数据库,但收到上述错误。我知道:

  1. 我已经设置了查看正确位置的路径 - 它显示在错误中。
  2. Python 是 64 位的。
  3. bin 文件夹位置包含一个 32 位 (ociw32.dll) 和一个 64 位 (oci.dll) 文件。

但是错误仍然告诉我架构是错误的。

在这方面的任何帮助都会很棒 - 我无法弄清楚问题可能出在哪里!

请您参考如下方法:

错误消息中提到的文件是 32 位 DLL,而不是 64 位 DLL——至少假设检查此类内容的逻辑是正确的!该代码使用此处提到的 imagehelp API:How can I test a Windows DLL file to determine if it is 32 bit or 64 bit? .还有一些其他方法可以验证 DLL 是 32 位还是 64 位。检查您的 PATH 并确保 64 位 Oracle Client 安装位于 PATH 中的第一个。下载并解压缩 64 位 Oracle Instant Client,以便快速轻松地进行测试。