[英]Getting Error Connect to Oracle using Python On Mac - Cannot locate Oracle Client library
I'm trying to connect to Oracle database in Python on Mac but getting the following error:我正在尝试在 Mac 上连接到 Python 中的 Oracle 数据库,但出现以下错误:
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". cx_Oracle.DatabaseError:DPI-1047:找不到 64 位 Oracle 客户端库:“dlopen(libclntsh.dylib, 1): image not found”。 See https://oracle.github.io/odpi/doc/installation.html#macos for help
请参阅https://oracle.github.io/odpi/doc/installation.html#macos寻求帮助
The code causing the error is dsn_tns = cx_Oracle.makedsn(host='', port='', service_name='') conn = cx_Oracle.connect(user='', password='', dsn=dsn_tns)导致错误的代码是 dsn_tns = cx_Oracle.makedsn(host='', port='', service_name='') conn = cx_Oracle.connect(user='', password='', dsn=dsn_tns)
Using the cx_Oracle Library使用 cx_Oracle 库
This is my lib folder这是我的 lib 文件夹
$ ls -la ~/lib $ ls -la ~/lib
total 274272总计 274272
drwxr-xr-x 7 staff 224 Jun 25 13:31. drwxr-xr-x 7 名员工 224 Jun 25 13:31。
drwxr-xr-x+ 113 staff 3616 Jun 25 14:20.. drwxr-xr-x+ 113 员工 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 名员工 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 lrwxr-xr-x 1 名员工 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 名员工 4803832 6 月 24 日 18:31 libclntshcore.dylib.19.1
-rwxr-xr-x@ 1 staff 8349944 Jun 24 18:30 libnnz19.dylib -rwxr-xr-x@ 1 名员工 8349944 6 月 24 日 18:30 libnnz19.dylib
-rwxr-xr-x@ 1 staff 125518764 Jun 24 18:31 libociei.dylib -rwxr-xr-x@ 1 名员工 125518764 Jun 24 18:31 libociei.dylib
MacOS: Catalina Version 10.15.5 Python 3.7.7 Oracle client MacOS:Catalina 版本 10.15.5 Python 3.7.7 Oracle 客户端
In cx_Oracle 8 there is a new initialization method that you can call in your scripts to specify the Instant Client directory:在 cx_Oracle 8 中有一个新的初始化方法,您可以在脚本中调用它来指定 Instant Client 目录:
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.您还可以在适当的站点包目录中添加符号链接,但我认为
init_oracle_client()
更容易。
Check the updated installation instructions and the new initialization documentation .检查更新的安装说明和新的初始化文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.