问题
I'm trying to connect to Oracle database in Python on Mac but getting the following error:
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help
The code causing the error is dsn_tns = cx_Oracle.makedsn(host='', port='', service_name='') conn = cx_Oracle.connect(user='', password='', dsn=dsn_tns)
Using the cx_Oracle Library
This is my lib folder
$ ls -la ~/lib
total 274272
drwxr-xr-x 7 staff 224 Jun 25 13:31 .
drwxr-xr-x+ 113 staff 3616 Jun 25 14:20 ..
lrwxr-xr-x 1 staff 61 Jun 24 18:03 libclntsh.dylib -> /Users/username/oracle/instantclient_19_3/libclntsh.dylib
lrwxr-xr-x 1 staff 51 Jun 25 13:31 libclntsh.dylib.19.1 -> /opt/oracle/instantclient_19_1/libclntsh.dylib.19.1
-rwxr-xr-x@ 1 staff 4803832 Jun 24 18:31 libclntshcore.dylib.19.1
-rwxr-xr-x@ 1 staff 8349944 Jun 24 18:30 libnnz19.dylib
-rwxr-xr-x@ 1 staff 125518764 Jun 24 18:31 libociei.dylib
MacOS: Catalina Version 10.15.5 Python 3.7.7 Oracle client
回答1:
In cx_Oracle 8 there is a new initialization method that you can call in your scripts to specify the Instant Client directory:
import platform
if platform.platform()[:6] == 'Darwin':
cx_Oracle.init_oracle_client(lib_dir="/Users/cjones/instantclient_19_3")
You can also add a symlink in the appropriate site-packages directory, but I think init_oracle_client() is easier.
Check the updated installation instructions and the new initialization documentation.
来源:https://stackoverflow.com/questions/62584718/getting-error-connect-to-oracle-using-python-on-mac-cannot-locate-oracle-clien