Linux安装cx_Oracles
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
從 下載鏈接 下載下面兩個文件
| 1 2 3 | 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、設置環境變量
| 1 2 3 4 | #?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,如下:
| 1 2 | 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/
| 1 2 3 | #?tar?-xf?cx_Oracle-5.0.4.tar.gz #?cd?cx_Oracle-5.0.4 #?python?setup.py?install |
測試:
| 1 2 3 4 5 | >>>?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.version 5.0.4 |
4、測試數據庫連接
| 1 2 3 4 5 | >>>?import?cx_Oracle?as?cx >>>?db=cx.connect('finchina/123456@192.168.1.236/orcl') >>>?print?db.version 11.2.0.1.0 >>>?db.close() |
FAQ整理:
問題1: conn0=cx.connect('finchina/123456@192.168.1.236:1521/orcl')
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle
解決方案:這里要保證你安裝的instantclient和需要連接的數據庫版本一致。下載
| 1 2 3 4 5 | oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip? instantclient-sdk-linux.x64-11.2.0.1.0.zip windows出現這個問題 復制?client下所有的.dll文件到python安裝包site_pageages目錄中即可 |
然后按照上文進行配置就即可。
問題2: conn0=cx.connect('finchina/123456@192.168.1.236: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
| 1 2 3 4 5 6 7 8 | 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
解決方案:
| 1 2 | cd?/opt/instantclient_11_2 ln?-sv?libclntsh.so.11.1?libclntsh.so |
本文轉自 ljohnmail 51CTO博客,原文鏈接:http://blog.51cto.com/ljohn/1940904,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的Linux安装cx_Oracles的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux中的压缩命令详细解析(一)
- 下一篇: Linux运维工程师:30道面试题整理