#rpm包下载地址
客户端oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm 下载地址:
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
模块cx_Oracle下载地址:
https://sourceforge.net/projects/cx-oracle/files/
#安装前,import cx_Oracle模块报错
[root@AWS-Dev-172-31-1-140 hadoop]# python
Python 2.7.9 (default, Apr 1 2015, 18:18:03)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cx_Oracle
#安装rpm包,先安装oracle客户端,再安装cx_Oracle模块包
[root@AWS-Dev-172-31-1-140 hadoop]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:oracle-instantclient11.2-basic-11################################# [100%]
[root@AWS-Dev-172-31-1-140 hadoop]# rpm -ivh cx_Oracle-5.1.2-11g-py27-1.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:cx_Oracle-5.1.2-1 ################################# [100%]
#设置环境变量
[root@AWS-Dev-172-31-1-140 hadoop]# cat >> /etc/profile <<!
# add by fjzcau,2016-03-24,config for oracle client which used by python
export ORACLE_HOME=/usr/lib/oracle/11.2/client64/lib
export LD_LIBRARY_PATH=\$ORACLE_HOME:\$LD_LIBRARY_PATH
export PATH=/usr/lib/oracle/11.2/client/bin:\$PATH
!
#安装后,在python目录下生成文件cx_Oracle.so
[hadoop@AWS-Dev-172-31-1-140 ~]$ ll /usr/lib/python2.7/site-packages
total 360
-rw-r--r-- 1 root root 898 Jul 6 2012 cx_Oracle-5.1.2-py2.7.egg-info
-rwxr-xr-x 1 root root 360085 Jul 7 2012 cx_Oracle.so
-rw-r--r-- 1 root root 119 Apr 2 2015 README
#验证安装是否成功
[root@AWS-Dev-172-31-1-140 hadoop]# su - hadoop
Last login: Fri Mar 25 10:48:33 CST 2016 from submit01 on pts/2
[hadoop@AWS-Dev-172-31-1-140 ~]$ python
Python 2.7.9 (default, Apr 1 2015, 18:18:03)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22661144/viewspace-2063620/
,如需转载,请注明出处,否则将追究法律责任。