ubuntu
- 从oracle官网下载两个必须的rpm包(这里选择的是version12.1.0.2.0, 64位操作系统)
oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
官网连接
sudo apt-get install alien dpkg-dev debhelper build-essential
- 把rmp copy到一个目录下,使用一下命令来把rpm转换成deb
sudo alien -d *.rpm
sudo dpkg -i *.deb
- 然后设置oracel环境变量, 这里是在 ~/.bashrc 文件中新增环境变量
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
source ~/.bashrc
sudo pip install cx_Oracle
import cx_Oracle
conn = cx_Oracle.connect('fkong/fkong@172.17.23.129/orcl')
cursor = conn.cursor ()
cursor.execute ("select * from dual")
row = cursor.fetchone ()
print row[0]
cursor.close ()
conn.close ()
mac os
instantclient-basic-macos.x64-11.2.0.4.0.zip
instantclient-sdk-macos.x64-11.2.0.4.0.zip
sudo mkdir -p /usr/lib/share/oracle/
#设置环境变量
export ORACLE_HOME=/usr/lib/share/oracle
export VERSION=11.2.0.3.0
export ARCH=x86_64
#把两个zip包的内容都解压到$ORACLE_HOME中
cd $ORACLE_HOME
tar -xzf instantclient-basic-$VERSION-macosx-x64.zip
tar -xzf instantclient-sdk-$VERSION-macosx-x64.zip
#建立软链接
ln -s libclntsh.dylib.11.2 libclntsh.dylib
ln -s libocci.dylib.11.2 libocci.dylib
#配置LIB的环境变量
export DYLD_LIBRARY_PATH=$ORACLE_HOME/
export LD_LIBRARY_PATH=$ORACLE_HOME/
env CFLAGS="-Qunused-arguments" ARCHFLAGS="-arch $ARCH" pip install cx_Oracle
- 如果遇到 【ld: library not found for -lgcc_s.10.5】错误
cd /usr/local/lib
sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib