【发布时间】:2019-04-17 16:07:00
【问题描述】:
我通过搜索发现了类似的问题。但是,之前的解决方案似乎以 Windows 而非 Linux 为中心。
1) Python 版本:Python 3.4.6
2) 操作系统版本:Linux SLES 12.3
3) Oracle 数据库版本:11.2
4) Oracle 客户端:64 位 11.2 即时客户端灯,cx-Oracle 6.4.1
5)LIBAIO:
S | Name | Summary | Type
---+---------------+------------------------------------------------------------+--------
i+ | libaio-devel | Development Files for Linux-native Asynchronous I/O Access | package
i | libaio1 | Linux-Native Asynchronous I/O Access Library | package
| libaio1-32bit | Linux-Native Asynchronous I/O Access Library | package
6) Oracle 客户端位置:/opt/pyora/oracle_11.2/instantclient_11_2
drwxrwxrwx 1 virtual wheel 346 Oct 23 07:48 .
drwxrwxrwx 1 virtual wheel 124 Oct 23 07:47 ..
-rwxrwxrwx 1 virtual wheel 25420 Aug 24 2013 adrci
-rwxrwxrwx 1 virtual wheel 449 Aug 24 2013 BASIC_LITE_README
-rwxrwxrwx 1 virtual wheel 439 Aug 24 2013 BASIC_README
-rwxrwxrwx 1 virtual wheel 47860 Aug 24 2013 genezi
-rwxrwxrwx 1 virtual wheel 53865194 Oct 22 16:44 libclntsh.so
-rwxrwxrwx 1 virtual wheel 53865194 Aug 24 2013 libclntsh.so.11.1
-rwxrwxrwx 1 virtual wheel 7996693 Aug 24 2013 libnnz11.so
-rwxrwxrwx 1 virtual wheel 1973074 Aug 24 2013 libocci.so.11.1
-rwxrwxrwx 1 virtual wheel 118738042 Aug 24 2013 libociei.so
-rwxrwxrwx 1 virtual wheel 9897206 Aug 24 2013 libociicus.so
-rwxrwxrwx 1 virtual wheel 164942 Aug 24 2013 libocijdbc11.so
-rwxrwxrwx 1 virtual wheel 2091135 Aug 24 2013 ojdbc5.jar
-rwxrwxrwx 1 virtual wheel 2739616 Aug 24 2013 ojdbc6.jar
-rwxrwxrwx 1 virtual wheel 192365 Aug 24 2013 uidrvci
-rwxrwxrwx 1 virtual wheel 66779 Aug 24 2013 xstreams.jar
7) 下面的代码设置环境变量以及尝试建立连接:(从 python 交互式 shell 运行)
from base64 import b64encode, b64decode # used for excoding/decoding base64 data
from toml import load as toml_load # used to retreive config file data
import cx_Oracle # used for accessing the Oracle databases
import os
import re
import sys
def decode_data(data):
return b64decode(data).decode('ascii')
path = os.environ["PATH"]
os.environ["PATH"] = "/opt/pyora/oracle_11.2/instantclient_11_2:" + path
os.environ["LD_LIBRARY_PATH"] = "/opt/pyora/oracle_11.2/instantclient_11_2"
os.environ["ORACLE_HOME"] = "/opt/pyora/oracle_11.2/instantclient_11_2"
os.environ["ORACLE_BASE"] = "/opt/pyora/oracle_11.2/instantclient_11_2"
username = decode_data("***")
password = decode_data("***")
hostname=decode_data("***")
port=decode_data("***")
schema=decode_data("***")
dsn ="{hostname}:{port}/{schema}".format(hostname=hostname,port=port,schema=schema)
print("PATH="+os.environ["PATH"]+"\n")
print("LS_LIBRARY_PATH="+os.environ["LD_LIBRARY_PATH"]+"\n")
print("ORACLE_HOME="+os.environ["ORACLE_HOME"]+"\n")
print("ORACLE_BASE="+os.environ["ORACLE_BASE"]+"\n")
dconn = cx_Oracle.connect(user=username,password=password,dsn=dsn)
8) 以下是收到的错误: 标准用户 -
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help
Sudo'd 用户 - (在导入 cx_Oracle 之后)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libnnz11.so: cannot open shared object file: No such file or directory
我已按照错误消息中的链接说明进行操作,但没有任何帮助。 https://oracle.github.io/odpi/doc/installation.html#linux
我确实验证了各个部分的架构:
Oracle 即时客户端: Instantclient-basic-linux.x64-11.2.0.4.0.zip
libaio:
libaio-devel-0.3.109-17.15.x86_64
libaio1-0.3.109-17.15.x86_64
Python 3:
Python 3.4.6 (default, Mar 01 2017, 16:52:22) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.architecture()
('64bit', 'ELF')
>>>
【问题讨论】:
-
首先想到的(不使用 SUSE 或 Oracle 产品)是您是否选择了正确的架构? 32 位还是 64 位?
-
哦,我真希望我能做出不使用 Oracle 或 SLES 的决定,但遗憾的是我被定向到了。 Oracle 客户端和 Python 3 都是 64 位的。这实际上是我检查的第一件事,因为这很容易出错。
-
用架构信息更新了上面的问题。
标签: python linux database cx-oracle sles