当前位置:   article > 正文

M1 mac环境下使用Python连接oracle数据库_libclntsh.dylib

libclntsh.dylib

问题描述

因oracle官方驱动暂无m1-arm版本,所以使用arm的python解释器报驱动错误,只能使用intel版本转译

cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 0x0001): tried: '/Users/xxx/software/oracle/instantclient_19_8/libclntsh.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), 'libclntsh.dylib' (no such file), '/usr/lib/libclntsh.dylib' (no such file), '/Users/xxx/software/oracle/instantclient_19_8/libclntsh.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/xxx/Project/PyProject/libclntsh.dylib' (no such file)". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
  • 1

安装

1、安装intel版本的Python3 任选一个安装即可
https://www.python.org/downloads/macos/
Python官网
2、使用pip安装cx_Oracle

pip3 install cx_Oracle
  • 1

3、下载oracle驱动
https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html
Oracle官网
4、解压到目录并配置环境变量
解压目录

# 需要将目录替换成自己的
# Oracle的OCI套件
export DYLD_LIBRARY_PATH=/Users/xxxx/software/oracle/instantclient_19_8
export PKG_CONFIG_PATH=/Users/xxxx/software/oracle
# 刷新环境变量 此处不一定都是该文件 根据terminal决定
source /etc/profile
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

使用方式

请注意此处使用Python intel解释器运行

import cx_Oracle
tns = '用户名/密码@IP地址:端口/sid'
db1 = cx_Oracle.connect(tns)
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/351546
推荐阅读
相关标签
  

闽ICP备14008679号