为什么要安装Oracle Instant Client
如果你需要在Python代码库中使用cx_oracle 访问数据库,就需要安装Oracle Instant Client
如果不安装,会报什么错?
Reason: tried: '/usr/local/lib/libnnz19.dylib' (no such file), '/usr/local/lib/libnnz19.dylib' (no such file), '/Users/shumao/miniconda3/envs/automation/bin/../lib/libnnz19.dylib' (no such file), '/usr/local/lib/libnnz19.dylib' (no such file), '/usr/lib/libnnz19.dylib' (no such file, not in dyld cache)". See https://oracle.github.io/odpi/doc/installation.html#macos for help
安装的两种方式:
第一种,下载Oracle Instant Client,在代码中指定Oracle Instant Client路径
cx-oracle.readthedocs.io/en/latest/u… 也就是这个文档中提供的方式
第二种,下载Oracle Instant Client,全局配置Oracle Instant Client路径
对于如何配置,在cx-oracle.readthedocs.io/en/latest/u… 文档中没有提到,我们可以参考这里 odpi-c.readthedocs.io/en/latest/u…
安装的三个步骤
- 手动下载安装包 或者 用脚本下载(推荐)
- 解压安装包
- 做配置文件让应用能够找到oracle licent library
手动安装时,如何找到需要下载的安装包
官方帮助文档在这里:odpi-c.readthedocs.io/en/latest/u… 对于手动安装,需要先下载DMG包。
Download the Basic or Basic Light 64-bit DMG from Oracle.
我们需要下载的是这个包:
解压安装包
- In Finder, double click on the DMG to mount it.
这一步的操作结果是弹出一个Finder窗口
Open a terminal window and run the install script in the mounted package, for example:
/Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru/install_ic.sh
复制配置文件让应用能够找到oracle client library
官方文档在这里:odpi-c.readthedocs.io/en/latest/u… 官方文档提供很多种配置方式,我选择的是直接复制需要的文件 /usr/local/lib下面去。
Or, instead of a link you can copy the required OCI libraries. For example:
cp /opt/oracle/instantclient_19_8/{libclntsh.dylib.19.1,libclntshcore.dylib.19.1,libons.dylib,libnnz12.dylib,libociei.dylib} /usr/local/lib/
注意:这里的 /opt/oracle/instantcient_19_8 指的就是上面下载的DMG包,所以将包路径替换成自己的就可以了。
如果在实际操作中,复制以上文件还是会报错,可以根据报错信息又复制以下文件到 /usr/local/lib 下面去。需要复制的文件存放在第二步的解压安装操作中最后复制到的文件夹那里。
cp libnnz19.dylib /usr/local/lib
cp libclntsh.dylib /usr/local/lib/