python cx_Oracle模組的安裝
最近需要寫一個資料遷移腳本,將單一Oracle中的資料遷移到MySQL Sharding集群,在linux下安裝cx_Oracle感覺還是有一點麻煩的,整理一下,做個總結。
對於Oracle客戶端,不只需要安裝對應的python模組(這裡我用了Oracle官方的python模組-cx_Oracle),還需要安裝Oracle Client,一般選擇Instant Client就夠了,還需要設定tnsnames.ora(當然也可以簡單的透過host:port/schema存取)。
安裝:
1. 先確定版本。因為我們的Oracle資料是在是有點老,所以我選了一個比較老的版本-Oracle Instant Client 10.2.0.4。
2. 下載instantclient-basic。下載網址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html。 。這裡要嚴重BS Oracle,居然要先註冊才能下載,這也算了,關鍵是註冊的時候,密碼居然要求有數字有字母,字母還要有大小寫,還必須至少8位。逼我搞了一個比我銀行密碼還要安全的密碼(好吧,現在我已經忘記我填了什麼了...),下basic就可以了。
$wget http://download.oracle.com/otn/linux/instantclient/10204/basic-10.2.0.4.0-linux-x86_64.zip
3.安裝配置
$unzip instantclient-basic-linux.x64-10.2.0.4.0.zip $cd instantclient_10_2 $cp * /usr/lib #直接放到动态库搜索路径中,不需要额外的环境配置 或 $unzip instantclient-basic-linux.x64-10.2.0.4.0.zip $cp -rf instantclient_10_2 /opt/ $vi /etc/profile export ORACLE_HOME=/opt/instantclient_10_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME $source /etc/profile
4.配置tnsnames.ora(可不用配置tns)
噁心,我一開始以為還要安裝什麼東東。
5.下載安裝cx_Oracle python模組
$wget http://downloads.sourceforge.net/project/cx-oracle/5.1.2/cx_Oracle-5.1.2-10g-py26-1.x86_64.rpm $rpm -ivh cx_Oracle-5.1.2-10g-py26-1.x86_64.rpm $ls /usr/lib/python2.6/site-packages/cx_Oracle.so #有这个文件表示安装成功,根据python的位置,也可能在其他地方,自己找一下吧
6.驗證及問題解決
$python >>import cx_Oracle
r. open shared object file: No such file or directory
表示沒有找到instant client的動態函式庫,check一下環境變數是否配置,是否生效,版本是否正確。
若報錯:ImportError: ./cx_Oracle.so: undefined symbol: PyUnicodeUCS4_Decode
Google的信息:There is nothing wrong with Debian. Python supports two incompatible modes of operation for Unicode, UCS2 (the default), and UCS4. Debian uses the default, Redhat uses UCS4. You need to recompile the extension for UCS-2 mode (i.e. using a Debian installation); this would fix the undefined symbol: PyUnicodeUCS4_Decode
所以重新編譯
使用:
1.基本連接–使用Oracle tns alias$./configure --prefix=/usr/local/python2.6.5 --enable-shared -enable-unicode=ucs4 $make;make install
2.用戶輸入密碼連接
如python script.py tp/tp@ocn_test
connection =cx_Oracle.connect("tp/tp@ocn_test") #查看tns alias命令 cmd>tnsping ocn_test TNS Ping Utility forLinux: Version 9.2.0.8.0-Production on 27-SEP-201110:47:48 Copyright (c) 1997, 2006, Oracle Corporation. Allrights reserved. Used parameter files: /opt/……/sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL =TCP)(HOST =10.20.36.19)(PORT =1520))) (CONNECT_DATA =(SID =ocntest))) OK (10msec)
4.使用Easy Connect語法,透過Drive連接資料庫
pwd =getpass.getpass() connection =cx_Oracle.connect("tp",pwd,"ocn_test")
6 .登陸as SYSDBA
connection =cx_Oracle.connect(sys.argv[1])
在Linux伺服器執行Oracle操作時報了一個錯誤:
connection =cx_Oracle.connect('tp','tp','10.20.36.19:1521/ocntest') #or connection =cx_Oracle.connect('tp/tp@10.20.36.19:1521/ocntest')
解決方式:
tns_name =cx_Oracle.makedsn('10.20.36.19','1521',' ocntest ') connection =cx_Oracle.connect('tp','tp',tns_name)解決方式/,一番折騰,最後使用第5種連接方式,瞬間解決此問題。 感謝閱讀,希望能幫助大家,謝謝大家對本站的支持! 更多python cx_Oracle模組的安裝和使用詳細介紹相關文章請關注PHP中文網!

使用NumPy創建多維數組可以通過以下步驟實現:1)使用numpy.array()函數創建數組,例如np.array([[1,2,3],[4,5,6]])創建2D數組;2)使用np.zeros(),np.ones(),np.random.random()等函數創建特定值填充的數組;3)理解數組的shape和size屬性,確保子數組長度一致,避免錯誤;4)使用np.reshape()函數改變數組形狀;5)注意內存使用,確保代碼清晰高效。

播放innumpyisamethodtoperformoperationsonArraySofDifferentsHapesbyAutapityallate AligningThem.itSimplifififiesCode,增強可讀性,和Boostsperformance.Shere'shore'showitworks:1)較小的ArraySaraySaraysAraySaraySaraySaraySarePaddedDedWiteWithOnestOmatchDimentions.2)

forpythondataTastorage,choselistsforflexibilityWithMixedDatatypes,array.ArrayFormeMory-effficityHomogeneousnumericalData,andnumpyArraysForAdvancedNumericalComputing.listsareversareversareversareversArversatilebutlessEbutlesseftlesseftlesseftlessforefforefforefforefforefforefforefforefforefforlargenumerdataSets; arrayoffray.array.array.array.array.array.ersersamiddreddregro

Pythonlistsarebetterthanarraysformanagingdiversedatatypes.1)Listscanholdelementsofdifferenttypes,2)theyaredynamic,allowingeasyadditionsandremovals,3)theyofferintuitiveoperationslikeslicing,but4)theyarelessmemory-efficientandslowerforlargedatasets.

文章討論了由於語法歧義而導致的Python中元組理解的不可能。建議使用tuple()與發電機表達式使用tuple()有效地創建元組。 (159個字符)

本文解釋了Python中的模塊和包裝,它們的差異和用法。模塊是單個文件,而軟件包是帶有__init__.py文件的目錄,在層次上組織相關模塊。

文章討論了Python中的Docstrings,其用法和收益。主要問題:Docstrings對於代碼文檔和可訪問性的重要性。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。