Python cx_Oracle错误。DPI-1047:找不到64位Oracle客户端库
我安装了库,尝试使用凭据访问jupyter笔记本中的SQL时,出现以下错误:Python cx_Oracle错误。DPI-1047:找不到64位Oracle客户端库,python,python-3.x,windows-10,cx-oracle,Python,Python 3.x,Windows 10,Cx Oracle,我安装了库,尝试使用凭据访问jupyter笔记本中的SQL时,出现以下错误: DatabaseError:DPI-1047:找不到64位Oracle客户端库:“找不到指定的模块”。请参阅以获取帮助您可能已经安装了cx\U Oracle Python库。为了通过jupyter notebook执行DB连接,您需要安装Oracle客户端,而这正是您的场景中缺少的。请按照以下步骤链接并安装Oracle客户端,这将解决您的问题: 确保已安装正确的oracle客户端(您可以从此处找到oracle客户端软件
DatabaseError:DPI-1047:找不到64位Oracle客户端库:“找不到指定的模块”。请参阅以获取帮助您可能已经安装了cx\U Oracle Python库。为了通过jupyter notebook执行DB连接,您需要安装Oracle客户端,而这正是您的场景中缺少的。请按照以下步骤链接并安装Oracle客户端,这将解决您的问题:
确保已安装正确的oracle客户端(您可以从此处找到oracle客户端软件包“”,并将下载的文件夹添加到安装python的文件夹中,然后将此位置(客户端软件包文件夹的位置)添加到系统的环境变量中。
希望能奏效。我建议您首先检查操作系统、Python和Oracle即时客户端体系结构的兼容性:
import platform
platform.architecture()
然后,我明确建议您在jupyter笔记本中设置Oracle Instant Client:
import os
os.environ["PATH"] = "Complete Location of Instant Client Folder" + ";" + os.environ["PATH"]
最简单的解决方案如下:
就是这样!简短的回答是:
cx\u Oracle.init\u Oracle\u客户端(lib\u dir=r“c:\path\u to\u库”)
以下是我为解决同一问题而遵循的步骤:
如果尚未安装cx\U Oracle,可以使用以下命令执行此操作:python-mpip安装cx\u Oracle--升级
可以找到cx_Oracle文档
使用以下命令验证是否已安装并识别所有内容:
import sqlalchemy as sqla
import pandas as pd
import cx_Oracle
# Test to see if it will print the version of sqlalchemy
print(sqla.__version__) # this returns 1.2.15 for me
# Test to see if the cx_Oracle is recognized
print(cx_Oracle.version) # this returns 8.0.1 for me
# This fails for me at this point but will succeed after the solution described below
cx_Oracle.clientversion()
在这一点上,我得到了一些错误,说找不到库。以下是解决方案:
import os
import platform
# This is the path to the ORACLE client files
lib_dir = r"C:\put_your_path_here\instantclient-basic-windows.x64- 19.9.0.0.0dbru\instantclient_19_9"
# Diagnostic output to verify 64 bit arch and list files
print("ARCH:", platform.architecture())
print("FILES AT lib_dir:")
for name in os.listdir(lib_dir):
print(name)
请确保更新特定于您的安装的lib_dir
路径。如果您有正确的路径,您将看到所有Oracle文件的列表,如:(adrci.exe、oci.dll、oci.sym等)。这是Python能够找到Oracle驱动程序所需的位置
当前(2020年11月)传递Windows Oracle库位置的方法是cx\u Oracle.init\u Oracle\u客户端(lib\u dir=r“c:\path\u to\u libraries”)
。以下是一个示例:
lib_dir = r"C:\put_your_path_here\instantclient-basic-windows.x64- 19.9.0.0.0dbru\instantclient_19_9"
try:
cx_Oracle.init_oracle_client(lib_dir=lib_dir)
except Exception as err:
print("Error connecting: cx_Oracle.init_oracle_client()")
print(err);
sys.exit(1);
此时,我可以运行以下错误而不出现任何错误:
# This works after passing the lib_dir path
cx_Oracle.clientversion() # For me it returns: (19, 9, 0, 0, 0)
已弃用以下是如何临时更新PATH变量:
以下方法可行,但现在首选的方法是使用cx\u Oracle.init\u Oracle\u客户端(lib\u dir=r“c:\path\u to\u libraries”)
import os
# Manually append the location of the ORACLE libraries to the PATH variable
os.environ["PATH"] = lib_dir + ";" + os.environ["PATH"]
根据上访问的文档 步骤1:安装cx\U Oracle
python -m pip install cx_Oracle --upgrade
步骤2:下载并解压缩Oracle Basic客户端
对于Windows,下载并解压缩客户端文件
步骤3:将Instatnt客户端位置告知cx_Oracle模块
如果您坚持使用文档并在c:\oracle
文件夹中提取它们,那么您的脚本可能如下所示
import cx_Oracle
cx_Oracle.init_oracle_client(lib_dir=r"C:\oracle\instantclient_19_9")
现在,您将摆脱这个错误。我在Anconda Spyder中遇到了这个错误 我就是这样修好的
MAC
完成后:python-mpip安装cx\u Oracle——升级
尝试:
如果您遇到以下问题:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
该错误表明您没有正确安装库。您是否遵循了它提供给您的链接?请检查Python、cx_Oracle和您的Oracle客户端库是否都是64位或32位。如何检查此错误?错误消息已经告诉您有一个64位Python。请按照消息中URL中的说明进行操作,这非常有用。i在UNIX中,有没有一种简单的方法可以解决相同的问题?在Linux上,您必须设置库搜索路径(例如,使用ldconfig或LD_library_路径-请参阅下载页面上的即时客户端安装说明)在Python进程之前starts@Naik:这是一种不好的做法。相反,将库文件的位置传递给Python,如cx\U Oracle中所述。有关详细信息,请参阅下面的我的答案。@Stan感谢您的评论。但这对我不起作用!使用
init\u Oracle\u客户端(lib\u dir=…)
适用于Windows和macOS,但不适用于Linux。这是有文档记录的。注意路径仅适用于Windows。它已被cx_Oracle 8的init_Oracle_客户端(lib_dir=xxx)所取代。
(这在Windows和macOS上很有用)新的“标准”是使用cx_Oracle 8的init_Oracle_客户端()
不要设置路径-请参阅Windows上的cx_Oracle 8,我建议使用,因为您可以将Instant Client和Python分开。您可以更新解决方案并用相关的cx_Oracle安装替换mysql软件包的pip安装吗?此外,这些说明遗漏了cx_Oracle如何知道Instant Client在哪里的重要步骤:on macOS使用init\u oracle\u client()
@ChristopherJones更新
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
import cx_Oracle
cx_Oracle.init_oracle_client(lib_dir="/Users/priyank.pathak/Downloads/instantclient_19_8")
## cx_Oracle.init_oracle_client(lib_dir="/Users/your_username/Downloads/instantclient_19_8")
cx_Oracle.clientversion()