Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library - Python

Tags:

I am establishing a connection to oracle 11g which is in a remote server using cx_oracle 7 with python 3.6.7. my OS in Ubuntu 18.04

I have installed oracle instant client library with libclntsh.so but I am not getting the expected output.

here is the code which i am using to connect to the oracle db

connection = cx_Oracle.connect("username/password@host/port") print (connection.version) connection.close() 

when the script runs i expect to get the connection version instead i am getting the following error message

File "script.py", line 13, in connection = cx_Oracle.connect("username/password@host/port") 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

like image 210
Ian Nato Avatar asked Apr 24 '19 06:04

Ian Nato


People also ask

Does cx_Oracle require Oracle client?

cx_Oracle requires Oracle Client libraries. The libraries provide the necessary network connectivity to access an Oracle Database instance.

What is Python cx_Oracle?

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions. cx_Oracle 8.3 was tested with Python versions 3.6 through 3.10.

What is Oracle Instant Client?

Oracle Instant Client enables development and deployment of applications that connect to Oracle Database, either on-premise or in the Cloud. The Instant Client libraries provide the necessary network connectivity and advanced data features to make full use of Oracle Database.


1 Answers

After some more research i got the solution from Ubuntu community , after you have installed oracle instant-client you will have to integrate oracle libraries as follows:

export LD_LIBRARY_PATH=/usr/lib/oracle/<version>/client(64)/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

An example for 12.1 version for Linux x86_64 can be:

export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

where <version> indicates the version of your of your oracle instant-client e.g 11.2, 12.2
The connection parameter should be as follows

connection = cx_Oracle.connect("username/password@host/service_name e.g orcl")

to get the listener/service_name type the following in the oracle sqlplus

SQL> show parameter local_listener 

literal under VALUE is your listener/service_name.

like image 182
Ian Nato Avatar answered Oct 11 '22 05:10

Ian Nato