Python cx_Oracle 错误 "DPI-1047: Cannot locate a 32-bit Oracle Client"

Python cx_Oracle error "DPI-1047: Cannot locate a 32-bit Oracle Client"

如何解决这个错误,我使用 python3.6 并且我使用 Oracle 数据库 11g,我想将我的 python 连接到 oracle 数据库,但是显示错误,我该如何解决?

这是我的代码:

#importing module
import cx_Oracle

#create a table in oracle database
try:
    con = cx_Oracle.connect('db_employees/root@localhost')

    #Now execute the sqlquery
    cursor = con.cursor()
    cursor.execute("insert into employees values(2171114103970002, raden, ceo, 01031997, batam, 001)")

    #commit that insert the provided database
    con.commit()
except cx_Oracle.DatabaseError as e:
    print("There is a problem with Oracle", e)

#by writing finally if any error occurs
#then also we can close the all database operation
finally:
    if cursor:
        cursor.close()
    if con:
        con.close()

这是消息错误:

C:\Python36>python "D:\testing.py"
There is a problem with Oracle DPI-1047: Cannot locate a 32-bit Oracle Client library: "The specified module could not be found". See https://oracle.github.io/odpi/doc/installation.html#windows for help
Traceback (most recent call last):
  File "D:\testing.py", line 20, in <module>
    if cursor:
NameError: name 'cursor' is not defined

检查您的路径以查看客户端是否在上面,在某些情况下路径未设置为指向客户端或其中包含无效字符并且 python 库无法访问它。

你可以在这里查看类似的问题https://github.com/oracle/python-cx_Oracle/issues/55

安装说明如下:Installing cx_Oracle on Windows

错误提示您需要 32 位 Oracle 客户端库。如果有人需要,您可以从 32-bit Windows Instant Client (The 64-bit libraries are here 获得一个)任何高达 19c 的版本都将连接到 Oracle DB 11.2。说明位于页面底部。确保安装了正确的 VS 可再发行组件。

我遇到了同样的问题,下面是我解决这个问题的步骤 -

  1. 从以下位置下载最新的 64 位版本的 oracle basic instantClient: https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html

就我而言,我已经下载了 - windows.x64-19.10.0.0.0dbru.zip

  1. 解压缩 Oracle instantClient 并复制所有 .dll 文件

  2. 将这些 .dll 文件从 Oracle instantclient 目录复制到 python 目录