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()
......
[火星人 ] linux環境下cx_Oracle的「ImportError: No module named cx_Oracle」已經有306次圍觀