Linux,连接Oracle,cx_Oracle.DatabaseError:DPI-1047找不到64位Oracle客户端库:“libclntsh.so

rbl8hiat  于 2023-08-03  发布在  Linux
关注(0)|答案(3)|浏览(173)

出现错误“cx_Oracle.DatabaseError:DPI-1047:找不到64位Oracle客户端库:“libclntsh.so:无法打开共享目标文件:没有这样的文件或目录“”。有关https://oracle.github.io/odpi/doc/installation.html#linux帮助,请参见www.example.com”
我看到https://oracle.github.io/odpi/doc/installation.html#oracle-instant-client-zip和How to fix: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library - Python
我一直在Windows上工作,只学习Linux系统。我需要这个问题的帮助。从Python连接到Oracle:

import cx_Oracle
con = cx_Oracle.connect('<USER>/<PASSWORD>@<HOST>:<PORT>/<SID>')

字符串
我从来没有从Linux连接。第一次

user@postgresql:~/opt$ cd oracle
user@postgresql:~/opt/oracle$ unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-basic-linux.x64-12.2.0.1.0.zip
inflating: instantclient_12_2/adrci  
inflating: instantclient_12_2/BASIC_README  
inflating: instantclient_12_2/genezi  
inflating: instantclient_12_2/libclntshcore.so.12.1  
inflating: instantclient_12_2/libclntsh.so.12.1  
inflating: instantclient_12_2/libipc1.so  
inflating: instantclient_12_2/libmql1.so  
inflating: instantclient_12_2/libnnz12.so  
inflating: instantclient_12_2/libocci.so.12.1  
inflating: instantclient_12_2/libociei.so  
inflating: instantclient_12_2/libocijdbc12.so  
inflating: instantclient_12_2/libons.so  
inflating: instantclient_12_2/liboramysql12.so  
inflating: instantclient_12_2/ojdbc8.jar  
inflating: instantclient_12_2/uidrvci  
inflating: instantclient_12_2/xstreams.jar
user@postgresql:~$ sudo apt install libaio1
user@postgresql:/etc/ld.so.conf.d$ sudo nano oracle-instantclient.conf
user@postgresql:/etc/ld.so.conf.d$ sudo ldconfig
user@postgresql:/etc/ld.so.conf.d$ sudo export 
LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH


Linux操作系统

user@postgresql:~$ cat /proc/version
Linux version 5.3.0-46-generic (buildd@lgw01-amd64-003) (gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2)) #38-Ubuntu SMP Fri Mar 27 17:37:05 UTC 2020

dzjeubhm

dzjeubhm1#

对于WSL Ubuntu
1.您将从https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html下载instantclient-basic和instantclient-sqlplus for linux的zip版本
1.创建名为/opt/oracle的文件夹

sudo mkdir -p /opt/oracle
cd /opt/oracle/

字符串
1.现在安装zip和libaio 1

apt-get install zip libaio1
cd /opt/oracle/


1.将instantclientbasic和sqlplus版本解压缩到创建的oracle文件夹中。

unzip /location/to/your/download/instantclient-basic-linux.x64-12.2.0.1.0.zip
unzip /location/to/your/download/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip


1.将目录更改为instantclient_12_2

cd instantclient_12_2/


1.运行以下命令

ln -s libclntsh.so.12.1 libclntsh.so
ln -s libocci.so.12.1 libocci.so


1.编辑.bashrc文件以设置oracle主目录。

sudo nano $HOME/.bashrc


1.将以下行添加到.bashrc的末尾

# set oracle home at the end of the file
export ORACLE_HOME=/opt/oracle/instantclient_12_2
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME:$PATH


1.还有

source $HOME/.bashrc


1.最后,安装cx_Oracle

u3r8eeie

u3r8eeie2#

问题解决了。也许它会很轻松:下载rpm(oracle-instantclient 12.2-basic、oracle-instantclient 12.2-devel、oracle-instantclient 12.2-devel)。
当然,只需要oracle-instantclient 12.2

sudo apt-get install oracle-instantclient12.2-basic-12.2.0.*

字符串
只需要添加到PATH:

user@postgresql:~$export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
user@postgresql:~$sudo ldconfig
user@postgresql:~$ sudo nano  /etc/profile.d/oracle.sh && sudo chmod o+r /etc/profile.d/oracle.sh
export PATH=$PATH:/usr/lib/oracle/12.2/client64/bin

ftf50wuq

ftf50wuq3#

我在使用Python的Debian 10镜像版本时也遇到了类似的问题,我按照以下步骤解决了我的docker镜像问题:
Step1:从Oracle官方网站下载oracle-instantclient19.19-basic-19.19.0.0.0-1.x86_64.rpm:
步骤2:安装在基础映像中
步骤3:我设置了以下ENV变量:
ENV ORACLE_HOME=/usr/lib/oracle/19.19/client64 ENV LD_LIBRARY_PATH=$ORACLE_HOME/lib
这解决了我的问题

相关问题