標籤:
系統內容:RHEL5.4 python2.5(手動編譯安裝,系統帶有2.4版本)
在使用python指令碼訪問資料庫時,需要匯入cx_Oracle模組
$>>>import cx_OracleTraceback (most recent call last): File "/ghca/monitor/async_Msg_MQDis/run.py", line 2, in <module> import async_Msg_MQDis File "/ghca/monitor/async_Msg_MQDis/async_Msg_MQDis.py", line 1, in <module> import cx_OracleImportError: No module named cx_Oracle分析原因:1、懷疑缺少模組包[[email protected] async_Msg_MQDis]$ rpm -qa|grep cxcx_Oracle-5.1.2-1發現已安裝,查詢包安裝目錄[[email protected] async_Msg_MQDis]$ rpm -ql cx_Oracle-5.1.2-1|less/usr/lib64/python2.4/site-packages/cx_Oracle.so/usr/share/doc/cx_Oracle-5.1.22、切換到模組目錄下進行匯入$cd /usr/lib64/python2.4/site-packages[[email protected] site-packages]$ pythonPython 2.5.2 (r252:60911, Apr 11 2013, 14:10:12) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import cx_OracleTraceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: ./cx_Oracle.so: undefined symbol: PyUnicodeUCS4_Decode>>> 3、猜測可能是python版本與cx_Oracle對應版本不一致匯入[[email protected] ~]$ ls /usr/bin/python2.4 /usr/bin/python2.4[[email protected] ~]$ /usr/bin/python2.4Python 2.4.3 (#1, Jun 11 2009, 14:09:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import cx_Oracle>>> 匯入成功總結:中途也曾重新下載cx_Oracle-5.1.2-10g-py25-1.i386.rpm和cx_Oracle-5.1.2-10g-py25-1.x86_64.rpm進行嘗試,均未匯入成功,並且在安裝了cx_Oracle*py25*.x86_64.rpm版本進行匯入時報缺少“libpython2.5.so.1.0”庫檔案錯誤。在公司測試機上裝有python2.6,其中 /usr/lib/libpython2.6.so.1.0 庫檔案屬於python-libs-2.6.6-20.el6.i686包。
Python匯入cx_Oracle報錯