Python 3.x cx_Oracle.DatabaseError:DPI-1072:使用Python 3.7不支持Oracle客户端库版本

Python 3.x cx_Oracle.DatabaseError:DPI-1072:使用Python 3.7不支持Oracle客户端库版本,python-3.x,oracle,cx-oracle,Python 3.x,Oracle,Cx Oracle,我试图通过Intellij Ultimate 2020.1使用Python 3.7在SQL Developer 19.4上运行简单脚本 我已经下载并安装了cx_Oracle python库,下载 Oracle Instant Client Basic软件包和SQL*Plus软件包,并将它们设置在同一文件夹中 以下是我的代码,出于安全原因,它会产生某些特定位遗漏的错误: import cx_Oracle import pyperclip lib_dir=r"<PATH>\i

我试图通过Intellij Ultimate 2020.1使用Python 3.7在SQL Developer 19.4上运行简单脚本

我已经下载并安装了cx_Oracle python库,下载 Oracle Instant Client Basic软件包和SQL*Plus软件包,并将它们设置在同一文件夹中

以下是我的代码,出于安全原因,它会产生某些特定位遗漏的错误:

import cx_Oracle
import pyperclip

lib_dir=r"<PATH>\instantclient_19_9"
cx_Oracle.init_oracle_client(lib_dir)

user=input("Please enter your username for the DB: ")
input("Please copy the password for <DB> Now, press enter here when complete") #Need to copy the password into clipboard so pyperclip can paste it in the password field for security

#Start the connection
connection = cx_Oracle.connect(user, pyperclip.paste(), "<HOST ADDRESS>") #Username,password,hostaddress

# Obtain a cursor
cursor = connection.cursor()

# Execute the query
sql = """<SQL QUERY>"""
cursor.execute(sql)

# Loop over the result set and save as a list
output=[]
for row in cursor:
    output=output.append(row)

print(output)

#Close the connection
cursor.close()
connection.close()
导入cx\u Oracle
进口pyperclip
lib_dir=r“\instantclient_19_9”
cx_Oracle.init_Oracle_客户端(lib_dir)
user=input(“请输入数据库的用户名:”)
输入(“请暂时复制密码,完成后按enter键”)#需要将密码复制到剪贴板中,以便pyperclip可以将其粘贴到密码字段中以确保安全
#启动连接
connection=cx_Oracle.connect(用户,pyperclip.paste(),“”)#用户名、密码、主机地址
#获取光标
cursor=connection.cursor()
#执行查询
sql=“”
cursor.execute(sql)
#在结果集上循环并另存为列表
输出=[]
对于光标中的行:
输出=输出。追加(行)
打印(输出)
#关闭连接
cursor.close()
连接。关闭()
当我运行此命令时,会出现以下错误:

文件“C:/Users/F694236/IdeaProjects/untitled1/.idea/5030testv0.py”,第5行,在 cx_Oracle.init_Oracle_客户端(lib_dir) cx_Oracle.DatabaseError:DPI-1072:不支持Oracle客户端库版本

我已经浏览了安装指南,但没有找到任何有效的解决方案

更新: 运行DPI_DEBUG_LEVEL为64的环境变量后,将给出以下输出:

ODPI [09396] 2020-11-27 09:52:28.968: load in parameter directory 
ODPI [09396] 2020-11-27 09:52:28.968: load in dir \\<PATH>\F694236\instantclient_19_9 
ODPI [09396] 2020-11-27 09:52:28.968: load with name \\<PATH>\F694236\instantclient_19_9/oci.dll
ODPI [09396] 2020-11-27 09:52:28.998: load by OS successful
ODPI [09396] 2020-11-27 09:52:28.998: validating loaded library
Traceback (most recent call last):
  File "<input>", line 3, in <module>
  File "C:<>\DEV\Tools\IntelliJUltimate\2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\<>\DEV\Tools\IntelliJUltimate\2020.1\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/F694236/IdeaProjects/untitled1/.idea/5030testv0.py", line 5, in <module>
    cx_Oracle.init_oracle_client(lib_dir)
cx_Oracle.DatabaseError: DPI-1072: the Oracle Client library version is unsupported
ODPI[09396]2020-11-27 09:52:28.968:加载到参数目录中
ODPI[09396]2020-11-27 09:52:28.968:在目录中加载\\\F694236\instantclient\U 19
ODPI[09396]2020-11-27 09:52:28.968:使用名称\\\F694236\instantclient\u 19\u 9/oci.dll加载
ODPI[09396]2020-11-27 09:52:28.998:操作系统加载成功
ODPI[09396]2020-11-27 09:52:28.998:验证加载的库
回溯(最近一次呼叫最后一次):
文件“”,第3行,在
文件“C:\DEV\Tools\IntelliJUltimate\2020.1\plugins\python\helpers\pydev\\u pydev\u bundle\pydev\u umd.py”,第197行,在runfile中
pydev_imports.execfile(文件名、全局变量、本地变量)#执行脚本
文件“C:\\DEV\Tools\IntelliJUltimate\2020.1\plugins\python\helpers\pydev\\u pydev\u imps\\u pydev\u execfile.py”,execfile中第18行
exec(编译(内容+“\n”,文件,'exec'),全局,loc)
文件“C:/Users/F694236/IdeaProjects/untitled1/.idea/5030testv0.py”,第5行,在
cx_Oracle.init_Oracle_客户端(lib_dir)
cx_Oracle.DatabaseError:DPI-1072:不支持Oracle客户端库版本

我的第一个问题是:您是否配置了环境变量

如果是,则Intellij可能会在您的路径中找到另一个版本的oci.dll,直到到达路径的末尾

我的建议是检查PATH环境变量,并检查路径中的每个目录中是否存在任何oci.dll

也许以下链接也会帮助您:

同时,如果相应地安装了Oracle客户端,您可以尝试以下解决方法:

dsn = cx_Oracle.makedsn(hostname, port_number, sid)
connection = cx_Oracle.connect(SCHEMA_NAME, SCHEMA_PASSWORD, dsn)
cursor = connection.cursor() 

我知道上述解决方法并不真正安全友好,但至少您可以尝试看看问题是否与Oracle客户端有关,或者您需要在其他地方搜索问题。

确保Oracle Instant Client与Python可执行文件的32位或64位相同。如果这不能解决问题,那么在启动Python之前,将环境变量DPI_DEBUG_LEVEL设置为64,并用它显示的内容更新您的问题-这将是用于加载Oracle客户端库的搜索路径。

使用
cx_Oracle.init_Oracle_客户端(lib_dir)
在cx_Oracle 8中,您不需要在Windows上设置路径。您好,我不完全确定你所说的环境变量是什么意思,我应该在哪里配置这些变量呢?我是IntelliJ的新手,因为我更习惯于使用JupyterWell,正如Christopher Jones所说,当使用cx_oracle 8时,您不再需要在Windows上设置路径。但是,要设置环境变量,请遵循以下步骤:是否已使用所需的信息进行更新?是否已安装所需的VS Redistributable?请参阅即时客户端下载页面。您使用的是什么操作系统?例如,在Windows XP中会出现该错误。