[英]Python and Oracle DB - “Error DPI-1050: Oracle Client library must be at version 11.2 or higher”
Some days ago, I was asked to develop a Python application capable of connecting to a Oracle DB. 几天前,我被要求开发一个能够连接到Oracle DB的Python应用程序。 Since I already have an Oracle client installed (version 12.2.0), I just pip installed cx_Oracle and tried to establish a connection using below code: 由于我已经安装了Oracle客户端(版本12.2.0),因此我只安装了cx_Oracle并尝试使用以下代码建立连接:
import pandas as pd
import cx_Oracle
connection = cx_Oracle.connect('username/password@service_as_described_in_tnsnames.ora')
cur=connection.cursor()
input("Press Enter to continue...")
cur.execute('select* from MY_PRETTY_TABLE')
for line in cur:
print()
cur.close()
connection.close()
But when trying to run it, I got the error " DPI-1050: Oracle Client library must be at version 11.2 or higher ". 但是,当尝试运行它时,出现错误“ DPI-1050:Oracle客户端库必须为11.2或更高版本 ”。 After googling it, I found this answer, and tried to change my code to: 谷歌搜索之后,我找到了这个答案,并尝试将我的代码更改为:
my_dsn = cx_Oracle.makedsn("host",port,sid="sid")
connection = cx_Oracle.connect(user="user", password="password", dsn=my_dsn)
cursor = connection.cursor()
querystring = "SQL query"
cursor.execute(querystring)
But still, same error. 但是,同样的错误。 It's important to notice that I have already used Oracle DB client in this same machine, to connect a DB with Power BI. 重要的是要注意,我已经在同一台计算机上使用Oracle DB客户端将数据库与Power BI连接。
Also, if it can be helpful, my paths are setted as: 另外,如果有帮助,我的路径设置为:
C:\instantclient_12_1
C:\Users\oracle2\product\12.1.0\client_1
C:\Users\oracle2\product\12.1.0\client_1\bin
C:\Users\oracle\product\12.2.0\dbhome_1\bin
That error implies that you have another older version of the Oracle client installed somewhere earlier in your PATH. 该错误意味着您在PATH的较早位置安装了另一个旧版本的Oracle客户端。 You should do a search for OCI.DLL on your machine (using where.exe or the dir command) and either move or remove any unnecessary copies or adjust PATH as needed. 您应该在计算机上搜索OCI.DLL(使用where.exe或dir命令),然后根据需要移动或删除任何不必要的副本或调整PATH。 Some older applications stuffed OCI.DLL in C:\\Windows\\System32 improperly, for example. 例如,某些较早的应用程序将OCI.DLL塞入了C:\\ Windows \\ System32中。
This problem had to do with Oracle Instant client Version 19.3.0.0.0. 此问题与Oracle Instant Client版本19.3.0.0.0有关。 I uninstalled it and installed the previous version Oracle Instant client 12.2.0.1.0 to and it worked. 我将其卸载并安装了先前版本的Oracle Instant Client 12.2.0.1.0,并且可以正常工作。 https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html
Important things to do before you try above: 在您尝试上述操作之前,需要做的重要事情:
From Windows command prompt 从Windows命令提示符
c:> where oci.dll
make sure you find only one entry and remove the redundant ones. 确保只找到一个条目并删除多余的条目。
Ensure you set the environment path to the newly installed client. 确保将环境路径设置为新安装的客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.