1. 概述:为了在我的macos上搭建python的cx_Oracle开发环境,首先需要配置oracle client
2. 环境与版本:
2.1. OS:Mac OS Sierra 10.12.2
2.2. JDK:1.8.0_91
2.3. Oracle client:Version 12.1.0.2 (64-bit) Updated 1/4/17 for Mac OS X (Intel x86)
PS:oracle网站的下载需要注册一个账户。请自行申请。下载
basic:http://download.oracle.com/otn/mac/instantclient/121020/instantclient-basic-macos.x64-12.1.0.2.0.zip
JDBC:http://download.oracle.com/otn/mac/instantclient/121020/instantclient-jdbc-macos.x64-12.1.0.2.0.zip
sqlplus:http://download.oracle.com/otn/mac/instantclient/121020/instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
odbc(可选):http://download.oracle.com/otn/mac/instantclient/121020/instantclient-odbc-macos.x64-12.1.0.2.0.zip
sdk(可选):http://download.oracle.com/otn/mac/instantclient/121020/instantclient-sdk-macos.x64-12.1.0.2.0.zip
Tools(可选):http://download.oracle.com/otn/mac/instantclient/121020/instantclient-tools-macos.x64-12.1.0.2.0.zip
这个是预编译版本,貌似需要pro*c,想深入了解的同学可以自己试试这个
http://www.oracle.com/technetwork/topics/precomp-112010-084940.html
2.4. cx_Oracle:cx_Oracle-5.2.1.tar.gz(需要使用brew安装pip或者pip3,再使用pip安装)(略)
3. 安装
3.1 MacOS安装:(略)
3.2 JDK安装:可以不装,不过为了让java的环境也可以正常运行,jdbc和java都要装上(略)
3.3 Oracle client:
#创建一个目录,把zip包都拷贝过来 mkdir /usr/local/oracle/ cd /usr/local/oracle/ mv /Users/eric/Downloads/instantclient-* . #解压到当前文件夹,四个包会解压到一个文件夹里 unzip instantclient-basic-macos.x64-12.1.0.2.0.zip #提供基本功能 unzip instantclient-sqlplus-macos.x64-12.1.0.2.0.zip #提供sqlplus命令行 unzip instantclient-jdbc-macos.x64-12.1.0.2.0.zip #提供jdbc unzip instantclient-tools-macos.x64-12.1.0.2.0.zip
unzip instantclient-sdk-macos.x64-12.1.0.2.0.zip #提供头文件,cx_Oracle会依赖其中的oci.h #进入到解压的目录中,连接一下库文件 cd instantclient_12_1 ln -s libclntsh.dylib.12.1 libclntsh.dylib ln -s libocci.dylib.12.1 libocci.dylib #修改profile文件,增加oracle客户端的目录和LD的库路径 export PATH=/usr/local/oracle/instantclient_12_1:$PATH
export DYLD_LIBRARY_PATH=/usr/local/oracle/instantclient_11_2:$DYLD_LIBRARY_PATH
source /etc/profile
#可以安装cx_Oracle了,我这有python2和3两个版本,所以两个都要安装
pip install cx_Oracle
pip3 install cx_Oracle
#sqlplus工具也可以使用了