http://ihavegotyou.iteye.com/blog/1812548
以下是在CentOS安装 cx_Oracle的流程:
- 准备阶段
- 确认操作系统是32位还是64位(getconf LONG_BIT)
- 确认当前python的版本(python --version)
- 确认你要连接的oracle server version(select * from v$version;)
- 确认有www.oracle.com的登录帐号
- 安装
- install instant client
- 登录到www.oracle.com上下载Oracle Instant Client
- 如果是64位的,请选择.*x86_64.rpm,否则是.*i386.rpm
- 如果是oracle 9i或更高,请选择Instant Client 11,如果是8或8i,请选择Instant Client 10
- 同时安装basic,devel,sqlplus(i.e. sudo rpm -ivh oracle-instantclient-basic-10.2.0.5-1.x86_64.rpm)
- 找到上述安装的位置并修改/etc/profile,添加类似如下:ORACLE_HOME="/usr/lib/oracle/10.2.0.5/client64"
PATH=$PATH:$ORACLE_HOME/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH - source /etc/profile
- install cx_Oracle
- 进入下载页面:http://sourceforge.net/projects/cx-oracle/files/5.1.2/
- 选择并下载对应的oracle版本,python版本,OS位数的rpm
- 安装(i.e. sudo rpm -ivh cx_Oracle-5.1.2-10g-py26-1.x86_64.rpm)
- 如果原先安装了错误的版本,可能需要先删除旧的
- 使用 python -v检查,找到cx_Oracle安装在哪个site-packages
- 如果存在多个site-packages,需要指定从哪个site-packages去查找cx_Oraclehttp://docs.python.org/2/library/site.html
- 如果以上都不成功,考虑自己编译安装
-
错误解决方案:ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory
输入:
locate libclntsh.so.10.1
获取对于路径
/app/oracle/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
编辑/etc/ld.so.conf
在最后一行输入获取的路径/oracle/product/10.2.0/db_1/lib/
执行sudo /sbin/ldconfig
- test
-
- #!/usr/bin/python
- import cx_Oracle
- connstr='user/pwd@yourhost:1521/yourserver_name/sid'
- conn = cx_Oracle.connect(connstr)
- curs = conn.cursor()
- curs.execute('select UTL_INADDR.get_host_address, sysdate from dual')
- print curs.description
- for row in curs:
- print row
- conn.close()
-
- install instant client