linux安装cx_Oracle模块

本文详细介绍如何在Linux 64位环境下配置Oracle 11.2客户端,包括下载精简版客户端、设置环境变量、安装依赖库等步骤,最终实现通过Python的cx_Oracle模块连接Oracle数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据库版本为11.2,linux环境64位

  1. http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html下载oracle的精简版客户端,instantclient-basic-linux.x64-11.2.0.4.0.zip和instantclient-sdk-linux.x64-11.2.0.4.0.zip,下载需要登录并且accept lisense,下载后传到linux上
  2. unzip解压缩instantclient-basic-linux.x64-11.2.0.4.0.zip和instantclient-sdk-linux.x64-11.2.0.4.0.zip到同一目录,我的目录叫cx_oracle_before,unzip instantclient-basic-linux.x64-11.2.0.4.0.zip -d ./cx_oracle_before,instantclient-sdk-linux.x64-11.2.0.4.0.zip解压同理,这个时候的我的路径是/root/cx_oracle_before/instantclient_11_2/,这时sdk目录也在/root/cx_oracle_before/instantclient_11_2/下
  3. 设置环境变量ORACLE_HOME=/root/cx_oracle_before/instantclient_11_2LD_LIBRARY_PATH=/root/cx_oracle_before/instantclient_11_2:.:/root/cx_oracle_before/instantclient_11_2/lib,/root/cx_oracle_before/instantclient_11_2/lib和.有可能是多于的路径,注意:如果是写在/etc/profile中,一定要source /etc/profile,source简单来说就是执行/etc/profile这个脚本,对所有shell有效,如果没有这一步,我出现的现象是能安装cx_Oracle,但是报错是ImportError: libclntsh.so.11.1: cannot open shared object file: No such file,这个错误的原因应该就是没有source /etc/profile
  4. 做一个软连接,cd $ORACLE_HOME,ln -s libclntsh.so.11.1 libclntsh.so,这步不做我报的错是error: command ‘gcc’ failed with exit status 1
  5. 这个时候可以pip install cx_Oracle了
  6. 进入python shell,import cx_Oracle报错ImportError: libaio.so.1: cannot open shared object file: No such file or directory,还需要安装yum install libaio*,安装libaio和libaio-devel两个库。
  7. import cx_Oracle成功,以上!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值