国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python cx_Oracle模塊的安裝和使用詳細介紹

2020-02-23 04:21:48
字體:
來源:轉載
供稿:網友

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)

注意tnsnames.ora其實并不存在,是要自己創建的(這個也很惡心,我一開始以為還要安裝什么東東。。),我沒有使用這種方式,有興趣的可以google一下。

 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

若報錯:import cx_Oracle gave ImportError: libclntsh.so.10.1: cannot 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            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平度市| 永昌县| 那坡县| 明星| 霍林郭勒市| 凭祥市| 张家口市| 甘南县| 海淀区| 平顶山市| 麻江县| 正镶白旗| 三门峡市| 绥芬河市| 和林格尔县| 浑源县| 泰安市| 富裕县| 深圳市| 开鲁县| 平度市| 东兰县| 吐鲁番市| SHOW| 滕州市| 陇川县| 清丰县| 咸阳市| 西城区| 祁连县| 乌鲁木齐县| 宜城市| 德安县| 南皮县| 运城市| 盐亭县| 周至县| 渭源县| 手机| 思南县| 盐津县|