linux环境下cx_Oracle的“ImportError: No module named cx_Oracle”错误。
环境:redhat AS5.0 + python2.7.2 + oracle instant client + cx_oracle
oracle instant client10.2.4.1 (linux)
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
需要用到的三个包的下载地址如下:
http://download.oracle.com/otn/linux/instantclient/10204/oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm
http://download.oracle.com/otn/linux/instantclient/10204/oracle-instantclient-basic-10.2.0.4-1.i386.rpm
http://download.oracle.com/otn/linux/instantclient/10204/oracle-instantclient-devel-10.2.0.4-1.i386.rpm
python2.7
http://cx-oracle.sourceforge.net/
下载的源码包是:cx_Oracle-5.0.4.tar.gz
环境变量:
export ORACLE_HOME=/usr/lib/oracle/10.2.0.4/client
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
遇到的问题:
在软件安装完毕,环境变量配置成功后,报错:“ImportError: No module named cx_Oracle”
解决:cx oracle官方下载源码包,编译后在安装,搞定了。
http://cx-oracle.sourceforge.net/,找到对应版本的“Source Code only”,下载后按照redme指示,
python setup.py build
python setup.py install
再次python import cx_Oracle,不报错了
[root@test ~]# python
Python 2.7.2 (default, Aug 1 2011, 13:44:53)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>>
—————-安装完成—————————–
测试代码
>>> import os
>>> import cx_Oracle
>>> os.environ['NLS_LANG']=”SIMPLIFIED CHINESE_CHINA.ZHS16GBK” #这句话是为了让oracle database中读出来的gbk编码中文正常显示而设设置的语言环境
>>> dsn = cx_Oracle.makedsn(“192.168.1.10″, “1521″, “db”)
>>> conn = cx_Oracle.connect(username, password, dsn)
>>> db_cursor = conn.cursor()
......