Linux安装cx_Oracles

简介:

Linux安装cx_Oracles

环境背景

系统:CentOS6.8

python:Python 2.7.13 |Anaconda 4.3.1 (64-bit)

cx_Oracle模块:5.0.4

Oracle:11.2.0.1.0

Oracle客户端:11.2.0.1.0

1、下载

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

从 下载链接 下载下面两个文件

1
2
3
oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip 
instantclient-sdk-linux.x64-11.2.0.1.0.zip
#注这里要根据连接数据库的版本来定,安装的客户端一定要选择基础版本,不要选instantclient11.2-basiclite


解压这两个文件到/opt/instantclient_11_2目录下

2、设置环境变量

1
2
3
4
# vim /etc/profile #文件尾部添加
export  ORACLE_HOME= /opt/instantclient_11_2/
export  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
# source /etc/profile

3、安装cx_Oracle

安装cx_Oracle之前需要先建立一个链接libclntsh.so,如下:

1
2
cd  /opt/instantclient_11_2/
ln  -s libclntsh.so.11.1 libclntsh.so

下载cx_Oracle

https://sourceforge.net/projects/cx-oracle/files/5.0.4/

1
2
3
# tar -xf cx_Oracle-5.0.4.tar.gz
# cd cx_Oracle-5.0.4
# python setup.py install

测试:

1
2
3
4
5
>>>  import  cx_Oracle
/root/ .pyenv /versions/anaconda2-4 .3.1 /lib/python2 .7 /site-packages/cx_Oracle-5 .0.4-py2.7-linux-x86_64.egg /cx_Oracle .py:3: UserWarning: Module cx_Oracle was already imported from  /root/ .pyenv /versions/anaconda2-4 .3.1 /lib/python2 .7 /site-packages/cx_Oracle-5 .0.4-py2.7-linux-x86_64.egg /cx_Oracle .pyc, but  /opt/cx_Oracle-5 .0.4 is being added to sys.path
>>>
>>> print cx_Oracle.version
5.0.4

4、测试数据库连接

1
2
3
4
5
>>>  import  cx_Oracle as cx
>>> db=cx.connect( 'finchina/123456@192.168.1.236/orcl' )
>>> print db.version
11.2.0.1.0
>>> db.close()

FAQ整理:

问题1: conn0=cx.connect('finchina/123456@192.168.1.236:1521/orcl')

cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

解决方案:这里要保证你安装的instantclient和需要连接的数据库版本一致。下载

1
2
3
4
5
oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip 
instantclient-sdk-linux.x64-11.2.0.1.0.zip
 
windows出现这个问题
复制 client下所有的.dll文件到python安装包site_pageages目录中即可

然后按照上文进行配置就即可。

问题2: conn0=cx.connect('finchina/123456@192.168.1.236:1521/orcl')

cx_Oracle.DatabaseError: ORA-28547: connection to server failed, probable Oracle Net admin error

解决方案:

重新安装 cx_Oracle5.0.4

重装安装 instantclient11.2-basic

下面选段来自Oracle客户端下载地址:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

1
2
3
4
5
6
7
8
Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
#注释:即时客户端软件包 - 基本:运行OCI,OCCI和JDBC-OCI应用程序所需的所有文件
oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip (48,338,185 bytes) (cksum - 15985569)
oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm (47,811,007 bytes) (cksum - 4244105838)
Instant Client Package - Basic Light: Smaller version of the Basic, with only English error messages and Unicode, ASCII, and Western European character  set  support
#注释:即时客户端软件包 - 基本轻量:较小版本的Basic,只有英文错误消息和Unicode,ASCII和西欧字符集支持,阿西吧!,原来是字符集问题
oracle-instantclient11.2-basiclite-11.2.0.1.0-1.x86_64.zip (20,825,489 bytes) (cksum - 133027975)
oracle-instantclient11.2-basiclite-11.2.0.1.0-1.x86_64.rpm (20,649,392 bytes) (cksum - 1121446971)

总结:

问题很严重,遇到问题,胡乱百度,无思路的Google,反而拖慢解决问题的节奏。希望这次之后,遇到任何问题都能:理清思路,将问题拆分,然后逐个击破

问题3:ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory

解决方案:

1
2
cd  /opt/instantclient_11_2
ln  -sv libclntsh.so.11.1 libclntsh.so



本文转自 ljohnmail 51CTO博客,原文链接:http://blog.51cto.com/ljohn/1940904,如需转载请自行联系原作者
相关文章
|
8天前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
58 0
|
9天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
27 0
|
9天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
15 0
|
9天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
34 0
|
20天前
|
Java Linux Maven
Linux中安装MAVEN环境配置
Linux中安装MAVEN环境配置
47 3
|
22天前
|
存储 负载均衡 索引
linux7安装elasticsearch-7.4.0集群配置
linux7安装elasticsearch-7.4.0集群配置
109 0
|
26天前
|
Linux 数据安全/隐私保护 虚拟化
Linux技术基础(1)——操作系统的安装
本文是龙蜥操作系统(Anolis OS) 8.4 的安装指南,用户可以从[龙蜥社区下载页面](https://openanolis.cn/download)获取ISO镜像。安装方法包括物理机的光驱和USB闪存方式,以及虚拟机中的VMware Workstation Pro设置。安装过程涉及选择语言、配置安装目标、选择软件集合和内核,设置Root密码及创建新用户。安装完成后,可通过文本模式或图形化界面验证系统版本,如Anolis OS 8.4,标志着安装成功。
|
29天前
|
边缘计算 Kubernetes Devops
KubeSphere平台安装系列之二【Linux单节点部署KubeSphere】(2/3)
KubeSphere平台安装系列之二【Linux单节点部署KubeSphere】(2/3)
35 3
|
21天前
|
消息中间件 Java Linux
Linux下RabbitMQ安装与使用
Linux下RabbitMQ安装与使用
32 1
|
29天前
|
边缘计算 Kubernetes Linux
KubeSphere平台安装系列之三【Linux多节点部署KubeSphere】(3/3)
KubeSphere平台安装系列之三【Linux多节点部署KubeSphere】(3/3)
26 1