Python cx_Oracle错误“ DPI-1047:找不到32位Oracle客户端”

时间:2019-07-29 08:43:23

标签: oracle oracle11g python-3.6 cx-oracle

如何解决此错误,我使用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

3 个答案:

答案 0 :(得分:0)

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

您可以在此处查看类似的问题https://github.com/oracle/python-cx_Oracle/issues/55

答案 1 :(得分:0)

以下是安装说明:https://cx-oracle.readthedocs.io/en/latest/installation.html#installing-cx-oracle-on-windows

该错误表明您需要32位Oracle客户端库。您可以从https://www.oracle.com/technetwork/topics/winsoft-085727.html中获得一个。任何版本都可以连接到Oracle DB 11.2。说明位于页面的底部。确保安装了正确的VS可再发行组件。

答案 2 :(得分:0)

我遇到了同样的问题,以下是我解决此问题的步骤 -

  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 文件 enter image description here

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

enter image description here