繁体   English   中英

使用 Python 连接到 Oracle DB

[英]Connection to Oracle DB with Python

我正在尝试使用 Python 连接到我的 Oracle 数据库。 我目前正在使用 cx_Oracle 与之连接,但不起作用...

#!/usr/bin/python3
import cx_Oracle

dsn_tns = cx_Oracle.makedsn('Host Name', 'Port Number', service_name='Service Name')

conn = cx_Oracle.connect(user=r'user', password='password', dsn=dsn_tns)

c = conn.cursor()
c.execute('select * from person')

conn.close()

错误:

conn = cx_Oracle.connect(user=r'g_user', password='G_user', dsn=dsn_tns)
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help

我去了网站,发现没有任何帮助......

我的代码中的某些内容是错误的还是其他内容?

确保您安装了正确的 oracle 客户端(您可以从这里找到 oracle 客户端包“https://www.oracle.com/in/database/technologies/instant-client/winx64-64-downloads.html”并添加将下载的文件夹放在安装 python 的文件夹中,然后将此位置(客户端包文件夹的位置)添加到系统的环境变量中。希望能奏效。

我建议您首先检查您的操作系统、Python 和 Oracle Instant Client 架构的兼容性:

import platform
platform.architecture()

然后,我绝对建议您在 jupyter notebook 中设置 Oracle Instant Client:

import os
os.environ["PATH"] = "Complete Location of Instant Client Folder" + ";" + os.environ["PATH"]

来源: cx_Oracle 错误。 DPI-1047:找不到 64 位 Oracle 客户端库

你的错误是

DPI-1047:找不到 64 位 Oracle 客户端库:“libclntsh.so:无法打开共享对象文件:没有这样的文件或目录”。

启动 Python 进程之前,您的操作系统搜索路径中需要 Oracle Linux 64 位客户端二进制文件。

最简单的方法是安装免费的Oracle Instant Client 使用最新的 19c 版本 - 它将让您连接到 Oracle DB 11.2 或更高版本。 安装说明位于下载页面的底部。 如果您安装 RPM,一切都已为您配置好。 如果您安装 ZIPS,我更喜欢使用ldconfig设置库搜索路径,这也显示在说明中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM