2

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
Rustam Pulatov
  • 625
  • 1
  • 9
  • 20

3 Answers3

2

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
Rustam Pulatov
  • 625
  • 1
  • 9
  • 20
0

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
Rustam Pulatov
  • 625
  • 1
  • 9
  • 20
  • 1
    Never set ORACLE_HOME for Instant Client. It's not an Oracle home installation. Just set your library search path, preferably with `ldconfig` as you did, and as shown in these [Linux x64 Instant Client installation instructions](https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html#ic_x64_inst). WIth this set, you don't need to set `LD_LIBRARY_PATH`. Also, you should use 19c which is really the renamed terminal release of the 12c line. It connects to the same DB versions as the 12.2 Instant Client. – Christopher Jones Apr 12 '20 at 06:41
  • @Christopher Jones, Thank you. I surprised, that no word about ORACLE_HOME in instruction. Now, it's understand. Tell me, please, need in "PATH" write path to instantclient? – Rustam Pulatov Apr 13 '20 at 03:54
  • On Linux you only need PATH if you have installed the tools with binaries. (With a special exception that the 19c sqlplus RPM package will create a link so PATH isn't needed just for that binary) – Christopher Jones Apr 14 '20 at 00:34
  • @ Christopher Jones Thank you! – Rustam Pulatov Apr 15 '20 at 08:41
0

I was facing similar issue with Debian 10 image version with python, I had followed below steps to resolve my docker image issue:

Step1 : downloaded oracle-instantclient19.19-basic-19.19.0.0.0-1.x86_64.rpm from Oracle official site:

Step 2: Installed in the base image

Step 3: I had setup following ENV variables:

ENV ORACLE_HOME=/usr/lib/oracle/19.19/client64 ENV LD_LIBRARY_PATH=$ORACLE_HOME/lib

This resolved my issue