這篇文章主要介紹了python安裝oracle擴展及資料庫連接方法,較為詳細的分析了Python下載oracle擴展及Windows、Linux環境下的安裝步驟、操作技巧及注意事項,需要的朋友可以參考下
本文實例講述了python安裝oracle擴充及資料庫連線方法。分享給大家供大家參考,如下:
下載:
cx_Oracle下載位址:cx-oracle.sourceforge.net/
instantclient-basic下載位址:www.oracle.com/technetwork/database/features/instant-client/index-097480.html
window環境:
python27 oracle10
需要軟體:
cx_Oracle-5.1.2-10g.win32-py2.7.msi
instantclient-basic-win32-10.2 .0.4.zip
1. 直接雙擊msi文件,即安裝cx_Oracle;
2. 解壓縮instantclient-basic-win32-10.2.0.4.zip ,將得到的.dll檔案全部拷貝到F:\Python27\Lib\site-packages目錄下
linux環境:
##python26 orracle10需要軟體:
cx_Oracle-5.1.2-10g-py26-1.x86_64.rpmbasic-10.2.0.4.0 -linux-x86_64.zip
2.(此處參考www.jb51.net/ article/106295.htm)
vi /root/.bash_profile增加如下兩行:
export ORACLE_HOME=/usr/local/instantclient_10_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME執行source /root/.bash_profile使變更生效
建立此連結庫的符號連結
cd $ORACLE_HOME ln -s libclntsh.so.x.x libclntsh.so
#重新安裝cx_Oracle
注意加--nodeps參數,否則也會回報上述錯誤[root@BJ-UPDATE-01 ~]# rpm -ivh -- nodeps cx_Oracle-5.0.1-10g-py24-1.x86_64.rpm#5.0.3版本不用加--nodeps參數
#測試:
#Python >>> import cx_Oracle >>> db = cx_Oracle.connect('user/psw@114.242.113.91:1521/orcl') >>> print db <cx_Oracle.Connection to user@114.242.113.91:1521/orcl> >>> cr=db.cursor() >>> cr.execute("select * from LOGININFO") <builtin.OracleCursor on <cx_Oracle.Connection to user@114.242.113.91:1521/orcl>> >>> rs=cr.fetchall() >>> print rs [('40288a8542746fd90142746fdbb50001', 'cccccc', 1, 1, None, None, None), ('40288a85427474b601427474b8270001', 'eeee', 1, 1, None, None, None), ('40288a854273bce0014273bee6310002', 'dddddd', 0, 0, None, None, None), ('40288a854274532d014274532f600001', 'cccccc', 1, 1, None, None, None), ('40288a8542747c750142747c77ac0001', 'eeee', 1, 1, None, None, None), ('40288a8542744fb30142744fb5e90001', 'cccccc', 1, 1, None, None, None)] >>>【相關推薦】1. 2. Python學習手冊
以上是oracle的安裝及資料庫連線的方法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!