oracle 驱动安装备忘

时间:2022-12-30 07:44:46

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

官网连接

  • 安装rpm转成deb的工具
sudo apt-get install alien dpkg-dev debhelper build-essential
  • 把rmp copy到一个目录下,使用一下命令来把rpm转换成deb
sudo alien -d *.rpm
  • 然后安装deb
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
  • 安装对应的python驱动
sudo pip install cx_Oracle
  • 编写python测试代码
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

  • 从oracle官网下载两个必须的zip包
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/
  • pip安装对应的python库
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