简体   繁体   中英

Linux. Connect ot Oracle. cx_Oracle.DatabaseError: DPI-1047 Cannot locate a 64-bit Oracle Client library: "libclntsh.so

I have error "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://oracle.github.io/odpi/doc/installation.html#linux for help"

I saw https://oracle.github.io/odpi/doc/installation.html#oracle-instant-client-zip and How to fix: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library - Python

I always work on Windows and only learing on Linux system. I need help for this issue. Connect to Oracle from python:

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

I never connected from Linux. It's first time.

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

Problem solved. Maybe It will be hlepfully: download rpm(oracle-instantclient12.2-basic, oracle-instantclient12.2-devel, oracle-instantclient12.2-devel).

of course, needs only oracle-instantclient12.2

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

Need only add to 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

For WSL Ubuntu

  1. you are going to download zip version for the instantclient-basic and the instantclient-sqlplus for linux from https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
  2. create a folder called /opt/oracle
sudo mkdir -p /opt/oracle
cd /opt/oracle/
  1. now install zip and libaio1
apt-get install zip libaio1
cd /opt/oracle/
  1. Unzip the instantclient basic, and sqlplus version to the created oracle folder.
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. change directory to instantclient_12_2
cd instantclient_12_2/
  1. run the following commands
ln -s libclntsh.so.12.1 libclntsh.so
ln -s libocci.so.12.1 libocci.so
  1. edit the.bashrc file to set oracle home.
sudo nano $HOME/.bashrc
  1. Add the following lines to the end of.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. And
source $HOME/.bashrc
  1. Finally, install cx_Oracle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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