Reputation: 93
I am trying to connect to an oracle database in a jupyter notebook environment using the cx_Oracle
library. I've set the settings and configurations then tried to start the connection with cx_Oracle.connect
but am getting this error:
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library
I've found solutions on how to fix this for python (installing instancclient for Oracle and placing dll files in the python directory, but how would I fix this issue for anaconda python to run the connection in a jupyter notebook?
Upvotes: 3
Views: 19358
Reputation: 466
Python is having a hard time finding Oracle instant client libraries on my Mac M1. Like bkyee mentioned, oracledb is a good work around since by default is doesn't need the oracle instant client. Here are the steps I use:
python -m pip install oracledb --upgrade
then change as needed for your setup
import pandas as pd
import oracledb
username = 'username'
password = 'password'
host = 'host.name.org'
port = 1521
service = 'SVC'
conn = oracledb.connect(user=username, password=password, host=host, port=port, service_name=service)
df = pd.read_sql_query("select table_name from all_tables", conn)
This site is helpful if you want some variations for oracledb connect.
Upvotes: 0
Reputation: 74
You may also change to python-oracledb, which Oracle client is not required.
python -m pip install oracledb
Upvotes: 2
Reputation: 9091
You definitely need to install an Oracle client library for it to work. Your issue is just how to get cx_oracle in your conda env to be able to locate the drivers on your computer.
Putting the dll in the python directory will work, but it's a sloppy fix - the official installation instructions say:
Add Oracle 21, 19, 18, 12 or 11.2 client libraries to your operating system library search path such as PATH on Windows or LD_LIBRARY_PATH on Linux. On macOS use init_oracle_client() in your application to pass the Oracle Client directory name, see Using cx_Oracle.init_oracle_client() to set the Oracle Client directory. This is also usable on Windows.
So once you have an Oracle Client installed, the easiest option is to use cx_Oracle.init_oracle_client():
import cx_Oracle
import sys
import os
cx_Oracle.init_oracle_client(lib_dir=r"C:\oracle\instantclient_19_9")
...the rest of your code...
Or you can add that directory to your PATH.
The installation instructions go into a lot more detail.
Upvotes: 0