Linux安裝cx_Oracles

來源:互聯網
上載者:User

標籤:oracle cx_oracle instantclient11.2 oracle用戶端 python

Linux安裝cx_Oracles

環境背景

系統:CentOS6.8

python:Python 2.7.13 |Anaconda 4.3.1 (64-bit)

cx_Oracle模組:5.0.4

Oracle:11.2.0.1.0

Oracle用戶端:11.2.0.1.0

1、下載

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

從 下載連結 下載下面兩個檔案

oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip instantclient-sdk-linux.x64-11.2.0.1.0.zip#注這裡要根據串連資料庫的版本來定,安裝的用戶端一定要選擇基礎版本,不要選instantclient11.2-basiclite


解壓這兩個檔案到/opt/instantclient_11_2目錄下

2、設定環境變數

# vim /etc/profile #檔案尾部添加export ORACLE_HOME=/opt/instantclient_11_2/export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME# source /etc/profile

3、安裝cx_Oracle

安裝cx_Oracle之前需要先建立一個連結libclntsh.so,如下:

cd /opt/instantclient_11_2/ln -s libclntsh.so.11.1 libclntsh.so

下載cx_Oracle

https://sourceforge.net/projects/cx-oracle/files/5.0.4/

# tar -xf cx_Oracle-5.0.4.tar.gz# cd cx_Oracle-5.0.4# python setup.py install

測試:

>>> import cx_Oracle/root/.pyenv/versions/anaconda2-4.3.1/lib/python2.7/site-packages/cx_Oracle-5.0.4-py2.7-linux-x86_64.egg/cx_Oracle.py:3: UserWarning: Module cx_Oracle was already imported from /root/.pyenv/versions/anaconda2-4.3.1/lib/python2.7/site-packages/cx_Oracle-5.0.4-py2.7-linux-x86_64.egg/cx_Oracle.pyc, but /opt/cx_Oracle-5.0.4 is being added to sys.path>>>>>> print cx_Oracle.version5.0.4

4、測試資料庫連接

>>> import cx_Oracle as cx>>> db=cx.connect(‘finchina/[email protected]/orcl‘)>>> print db.version11.2.0.1.0>>> db.close()

FAQ整理:

問題1: conn0=cx.connect(‘finchina/[email protected]:1521/orcl‘)

cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

解決方案:這裡要保證你安裝的instantclient和需要串連的資料庫版本一致。下載

oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip instantclient-sdk-linux.x64-11.2.0.1.0.zipwindows出現這個問題複製 client下所有的.dll檔案到python安裝包site_pageages目錄中即可

然後按照上文進行配置就即可。

問題2: conn0=cx.connect(‘finchina/[email protected]:1521/orcl‘)

cx_Oracle.DatabaseError: ORA-28547: connection to server failed, probable Oracle Net admin error

解決方案:

重新安裝 cx_Oracle5.0.4

重裝安裝 instantclient11.2-basic

下面選段來自Oracle用戶端:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications#注釋:即時用戶端軟體包 - 基本:運行OCI,OCCI和JDBC-OCI應用程式所需的所有檔案oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip (48,338,185 bytes) (cksum - 15985569)oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm (47,811,007 bytes) (cksum - 4244105838)Instant Client Package - Basic Light: Smaller version of the Basic, with only English error messages and Unicode, ASCII, and Western European character set support#注釋:即時用戶端軟體包 - 基本輕量:較小版本的Basic,只有英文錯誤訊息和Unicode,ASCII和西歐字元集支援,阿西吧!,原來是字元集問題oracle-instantclient11.2-basiclite-11.2.0.1.0-1.x86_64.zip (20,825,489 bytes) (cksum - 133027975)oracle-instantclient11.2-basiclite-11.2.0.1.0-1.x86_64.rpm (20,649,392 bytes) (cksum - 1121446971)

總結:

問題很嚴重,遇到問題,胡亂百度,無思路的Google,反而拖慢解決問題的節奏。希望這次之後,遇到任何問題都能:理清思路,將問題拆分,然後逐個擊破

問題3:ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory

解決方案:

cd /opt/instantclient_11_2ln -sv libclntsh.so.11.1 libclntsh.so


本文出自 “Ljohn” 部落格,謝絕轉載!

Linux安裝cx_Oracles

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.