4

I have found similar questions by searching. However, the previous solutions seem to be centered around Windows and not Linux.

1) Python version: Python 3.4.6

2) OS version: Linux SLES 12.3

3) Oracle DB Version: 11.2

4) Oracle Client: 64-bit 11.2 instant client light, 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 Client Location: /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) The code below sets the environment variables as well as attempts to make a connection: (run from python interactive 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) Below is the errors received: Standard User -

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 User - (right after import 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

I have follow the instructions for the link found in the error message, but it was of no help. https://oracle.github.io/odpi/doc/installation.html#linux

I did verify architecture on the various parts:

Oracle instant client: 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')
>>>
Majisto
  • 93
  • 1
  • 2
  • 6
  • The first thing that springs to mind (not using SUSE or Oracle products) is if you chose the correct architecture? 32 vs 64 bit? – tink Nov 14 '18 at 16:40
  • 1
    Oh I so wish I could make the decision on not using Oracle or SLES, but sadly I am directed to. Both the Oracle client and Python 3 are 64 bit. That was actually the first thing I checked, as it would be an easy mistake. – Majisto Nov 14 '18 at 16:49
  • 1
    Updated the question above with architecture info. – Majisto Nov 14 '18 at 17:03

1 Answers1

2

Set the library search path before starting your application. I recommend using ldconfig, as shown on the ODPI-C installation link and the actual cx_Oracle installation doc.

With Instant Client do not set ORACLE_HOME or ORACLE_BASE. And why set PATH inside the application??

I would also recommend using Instant Client 18.3, which can connect to Oracle Database 11.2 onwards.

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
  • Thank you, you are a rockstar!!! Your suggestion worked. Let me explain a bit why we were doing what we were doing. First.. I am no DBA especially Oracle. When I tried using 11.x and 12.x with a different version DB the connection would be horrendously slow. So to get around this on my workstation I set the path as the script ran. This didn't translate well to the server. As we have no Oracle 18 DBs I refrained from using that client. But following you suggestion, it worked fine with the older DBs so I will update our procedures accordingly. - pt1 – Majisto Nov 16 '18 at 19:38
  • 1
    pt 2 - As for using ORACLE_HOME and ORACLE_BASE, those were other suggestions I saw on other post solutions. I had tried setting the PATh and LD_LIBRARY_PATH with the older clients and still had issues. So,I went back to setting in the script for expediency .. nothing else. Thanks again. – Majisto Nov 16 '18 at 19:41
  • @Christopher Jones .. Hi Jones. We dont have any Instant client installed in our Linux server. Can i use existing oracle version with "cx_Oracle" because we dont have flexibility to install instant client. Please help me with any suggestion how can we connect cx_Oracle without Instant client – avinash Aug 20 '19 at 11:49
  • @Majisto. By changing environmental variables like ORACLE_HOME , ORACLE_BASE did the script ran fine ? Can you help me with some syntax – Arya Aug 21 '19 at 03:18
  • The cx_Oracle installation instructions are here: https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html – Christopher Jones Aug 21 '19 at 12:34