需要安装驱动
- basic
- sdk
- sqlplus
下载地址
https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html
-
目前并不支持 arm64
- instantclient-basic-macos.x64-11.2.0.4.0.zip
- instantclient-basic-macos.x64-11.2.0.4.0.zip
- instantclient-sdk-macos.x64-11.2.0.4.0.zip
-
全部加压放到一个目录
-
instantclient-11.2
设置环境变量
- vim ~/.bash_profile
export ORACLE_HOME=/Users/jimogangdan/Downloads/instantclient_11_2
export DYLD_LIBRARY_PATH=/Users/jimogangdan/Downloads/instantclient_11_2
export PKG_CONFIG_PATH=/Users/jimogangdan/Downloads/instantclient_11_2
export PATH=$ORACLE_HOME:$PATH
export NLS_LANG=.AL32UTF8
pthon 代码
import cx_Oracle
dsn = cx_Oracle.makedsn(host='localhost', port=1521, sid='xe')
with cx_Oracle.connect(user=r'fdm', password='qwe123', dsn=dsn) as connection:
with connection.cursor() as cursor:
sql = """select sysdate from dual"""
for r in cursor.execute(sql):
print(r)
报错 找不到 连接文件
- opendl( libclntsh.dylib ) no such file /usr/lib/libnnz11.dylib no such file
想到把 ibnnz11.dylib 复制到 /usr.lib
- /usr/lib 没有权限sip 保护
- 无奈进去恢复模式 设置限制
但是重启之后 read only file system
- 然后复制 显示 cross deviece
检索发现 可以设置
- x_Oracle.init_oracle_client()
- lib_dir config_dir
- 但是依然没用
然后发现一个.net 项目
- https://www.devart.com/odbc/oracle/
- 可以安装的 pkg devartodbcoracle.pkg
然后重新设置 DYLD_LIBRARY_PATH
- 提示 libso