Getting Error Connect to Oracle using Python On Mac - Cannot locate Oracle Client library

自作多情 提交于 2021-01-29 08:40:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!