Setting up anything Oracle related is a huge pain. After hunting the web for info with minimal success, I have decided to create a small tutorial to walk through setting up cx_Oracle to connect to Oracle installations.

Prerequisites

If you do not have a Oracle.com account, you will unfortunately need to create one to be able to download anything. Once you have your account head to the OS Selection page and select the appropriate OS, in my case this will be Linux / AMD64. On the subsequent page you must download the basiclite package as well as the devel package. I chose the RPM files as I am running CentOS 6.x. If you want non-English application support you probably want to install the basic version instead of the basiclite, it has multilingual support built in. You may optionally want to install the sqlplus package to help with debugging and connection issues.

Oracle Library Installation

I downloaded the RPM files so ill use the rpm command to install the packages as follows

1
2
3
4
5
6
7
[root@devel ~] # cd oracle_files
[root@devel oracle_files]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm
Preparing... ########################################### [100%]
1:oracle-instantclient11.########################################### [ 33%]
2:oracle-instantclient11.########################################### [ 67%]
3:oracle-instantclient11.########################################### [100%]
[root@devel oracle_files]#

This will install the client under /usr/lib/oracle/11.2/client64/ by default under CentOS. Now this path is not listed under the shared library path by default (why doesn't this get setup by default?), so we must add it. Create the following file: /etc/ld.so.conf.d/oracle.conf with the following contents, adjusted accordingly to your installation:

1 /usr/lib/oracle/11.2/client64/lib

With that in place we can now enable the shared library path system wide as follows:

1 [root@devel ~]# ldconfig

To verify the library path installation you can try and run the sqlplus client. If it fails to start then you have a problem and should look into any mistakes that may have occurred during the installation process.

1
2
3
4
5
6
[root@devel ~]# PATH=$PATH:/usr/lib/oracle/11.2/client64/bin # place in ~/.bashrc for a permanent setup
[root@devel ~]# sqlplus
SQL*Plus: Release 11.2.0.3.0 Production on Mon Jun 11 16:57:40 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.

Python Library Installation

With the oracle libraries installed we can now begin installing the python connector cx_Oracle. I will be building a rpm file from the source rpm. If you are not using CentOS, or don't want to build a rpm for whatever reason, then go ahead and grab the source tarball instead.

Building and installing from source rpm:

1
2
3
4
5
6
7
8
[root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.src.rpm
1:cx_Oracle ########################################### [100%]
[root@devel ~]# cd ~/rpmbuild/SPECS
[root@devel ~]# yum install rpm-build
[root@devel ~]# ORACLE_HOME=/usr/lib/oracle/11.2/client64/ rpmbuild -ba cx_Oracle.spec
[root@devel ~]# cd ../RPMS/x86_64
[root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.x86_64.rpm
Preparing... ########################################### [100%]
1:cx_Oracle ########################################### [100%]

Or Building and installing from source tarball

1
2
3
4
tar xvfz cx_Oracle.tar.gz
cd cx_Oracle.tar.gz
ORACLE_HOME=/usr/lib/oracle/11.2/client64/ python setup.py build
ORACLE_HOME=/usr/lib/oracle/11.2/client64/ python setup.py install

Verification

To easily test if the installation has succeded run the following 1 liner, if no errors occur then your installation went OK.

1 [root@devel x86_64]# python -c 'import cx_Oracle'

在CentOs6.x 安装Cx_oracle5.x的更多相关文章

  1. vmware Centos6.6安装64位

    Centos6.6安装64位 必须开启BIOS中的虚拟化技术 首先开机进入BIOS,一般机器是按F2,我的T420是按F1,然后进入Security,Virtualization,选择Enable即可 ...

  2. Gitlab完美安装【CentOS6.5安装gitlab-6.9.2】

    摘要: 拆腾了几天,终于在今天找到了快速安装Gitlab的方法.CentOS6.5安装gitlab-6.9.2 参考网址:https://gitlab.com/gitlab-org/omnibus-g ...

  3. CentOS6.5安装Tomcat

    安装说明 安装环境:CentOS-6.4 安装方式:源码安装 软件:apache-tomcat-7.0.56.tar.gz 下载地址:http://tomcat.apache.org/download ...

  4. Centos6 yum安装openldap+phpldapadmin+TLS+双主配置

    原文地址:http://54im.com/openldap/centos-6-yum-install-openldap-phpldapadmin-tls-%E5%8F%8C%E4%B8%BB%E9%8 ...

  5. centos6.5安装oracle11g_2

    centos7安装oracle数据库不成功,换成centos6.5安装,可以安装成功,记录一下 安装系统时,主机名如果不是用localhost,安装成功后,要用主机名和ip做映射,修改/etc/hos ...

  6. CentOS6.6安装vmware workstation报错

    本人系统用的是centos6.6,安装了vmware workstation,启动后一直如下图报错,相关内核已经安装了的,哪位前辈如果解决过这样的问题,麻烦指点指点,小弟在此先谢过了.

  7. CentOS6.6安装virtualbox4.1.44

    本人用的是centos6.6,安装了virtualbox 4.1.44,启动后一直如上图报错,哪位前辈如果解决过这样的问题,麻烦指点指点,小弟在此先谢过了.

  8. [转]CentOS-6.3安装配置cmake

    CentOS-6.3安装配置cmake   zhoulf 2013-02-03 原创 安装说明 安装环境:CentOS-6.3安装方式:源码编译安装 软件:cmake-2.8.10.2.tar.gz下 ...

  9. 实战CENTOS6.5安装docker并创建asp.net mvc 5 镜像,运行MVC 网站

    Docker,容器,让研发.测试.生产同一环境,可在linux平台上混合使用JAVA与net 程序 Centos6.5安装docker 参考http://my.oschina.net/kcw/blog ...

随机推荐

  1. 拦截recyclerview 的item 的点击事件

    recyclerview.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(),recyclerview, new Re ...

  2. Pixhawk之姿态解算篇(1)_入门篇(DCM Nomalize)

    一.开篇 慢慢的.慢慢的.慢慢的就快要到飞控的主要部分了,飞控飞控就是所谓的飞行控制呗,一个是姿态解算一个是姿态控制,解算是解算,控制是控制,各自负责各自的任务.我也不懂.还在学习中~~~~ 近期看姿 ...

  3. Ubuntu切换至root错误:su:Authentication failure解决

    当前用户切换到root出现这个错误的原因是没有创建root用户,解决如下: 1.打开终端,输入命令sudo passwd root 会提示输入新的用户密码,输入后会再确认一次,成功后会显示:passw ...

  4. C#应用程序配置文件.config介绍

    我们经常会希望在程序中写入一些配置信息,例如版本号,以及数据库的连接字符串等.你可能知道在WinForm应用程序中可以利用Properties.Settings来进行类似的工作,但这些其实都利用了Ap ...

  5. 关于 AlphaGo 论文的阅读笔记

    这是Deepmind 公司在2016年1月28日Nature 杂志发表论文 <Mastering the game of Go with deep neural networks and tre ...

  6. BZOJ 3727 PA2014 Final Zadanie 树形DP

    题目大意:给定一棵树,令一个点到全部点的距离与点权的乘积之和为b[i].求每一个点的权值a[i] 首先假设给定a[i]我们能够非常轻松的求出b[i] 可是反过来怎么搞?高斯消元?30W? 考虑已知a[ ...

  7. C语言-回溯例4

    1,问题提出 日本数学家桥本吉彦教授于1993年10月在我国山东举行的中日美三国数学教育研讨会上向与会者提出以下填数趣题: 把1,2,...,9这9个数字填入下式的九个方格中(数字不得重复),使下面 ...

  8. 使用 Navicat 8.0 管理mysql数据库(导出导入数据)

    http://dxcns.blog.51cto.com/1426423/367105 使用Navicat For MySql 将mysql中的数据导出,包括数据库表创建脚本和数据 (1)数据的导出:右 ...

  9. PHP读取远程文件的4种方法

    1. fopen, fread1 if($file = fopen("http://www.example.com/", "r")) {2 while(!feo ...

  10. nightwatch testing 注意事项

    coding style 好的測試項目應該盡量不要使用pause 並且要有驗證的機制 .click('input.btn') //.pause(3000) .waitForElementVisible ...