Reputation:
I am trying to connect to my Oracle Database with Python. I am currently using cx_Oracle to connect with it but doesnt work...
#!/usr/bin/python3
import cx_Oracle
dsn_tns = cx_Oracle.makedsn('Host Name', 'Port Number', service_name='Service Name')
conn = cx_Oracle.connect(user=r'user', password='password', dsn=dsn_tns)
c = conn.cursor()
c.execute('select * from person')
conn.close()
Error:
conn = cx_Oracle.connect(user=r'g_user', password='G_user', dsn=dsn_tns)
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://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
I went on the Site and found nothing that could help...
Is something in my Code Wrong or is it something else ?
Upvotes: 2
Views: 3243
Reputation: 10721
Your error is
DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory".
You need the Oracle Linux 64-bit client binaries in your operating system search path before you start the Python process.
The easiest way is to install the free Oracle Instant Client. Use the latest 19c version - it will let you connect to Oracle DB 11.2 or later. The install instructions are at the foot of the download page. If you install the RPMs, everything is configured for you. If you install the ZIPS I prefer setting the library search path with ldconfig
which is also shown in the instructions.
Upvotes: 0
Reputation: 2013
Make sure you have installed the correct oracle client (you can find the oracle client package from here "https://www.oracle.com/in/database/technologies/instant-client/winx64-64-downloads.html" and add the downloaded folder inside the folder where python is installed and then add this location (location of your client package folder) to system's environment variable. Hope that will work.
I suggest you to first check the compatibility of your OS, Python and Oracle Instant Client architecture:
import platform
platform.architecture()
Then, I definitely advise you to set the Oracle Instant Client inside your jupyter notebook:
import os
os.environ["PATH"] = "Complete Location of Instant Client Folder" + ";" + os.environ["PATH"]
Source: cx_Oracle error. DPI-1047: Cannot locate a 64-bit Oracle Client library
Upvotes: 1