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

Connecting to Oracle Database with cx_oracle gives DPI-1047 on Windows

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.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 -- 至少假设检查此类内容的逻辑是正确的!该代码使用此处提到的图像帮助 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 以便快速轻松地进行测试。