一,想訪問遠程Oracle數據庫,本地又不想安裝幾百兆的Oracle Client(也木有root權限),安裝python的cx_Oralce 模塊須要依賴Oracle Instant Client 代替完整的Oracle Client。html
Oracle Instant Client 下載:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.htmlpython
下載:mysql
instantclient-basic-linux.x64-11.2.0.4.0.zip
instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
instantclient-sdk-linux.x64-11.2.0.4.0.zip
解壓文件放到以下目錄:linux
$HOME/oracle/instantclient_11_2
拷貝tnsnames.ora文件,在/home/oracle/instantclient_11_2目錄下建立network/admin目錄,並將tnsnames.ora文件拷貝進去(這個貌似不是必要條件,出了問題的話就補上吧)web
~/.bashrc設置:sql
export ORACLE_HOME=$HOME/oracle/instantclient_11_2 export TNS_ADMIN=$ORACLE_HOME/network/admin export DYLD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$ORACLE_HOME:$PATH
下面就是該安裝cx_Oracle的python模塊了,下載直接python setup.py installshell
因爲非root的權限,會報無/lib64/python2.6/site-packages/目錄讀寫權限數據庫
能夠改寫python的安裝目錄vim
export PYTHONPATH=$HOME/.local/lib64/python2.6/site-packages/
export PATH=$HOME/.local/bin:$PATHbash
而後source .bashrc生效
接下來能夠安裝了:python setup.py install --prefix=~/.local (牛逼閃閃啊,直接在原目錄前加了個本地目錄前綴,華麗麗的解決非root的壁壘)
順其天然的又報錯了(奔潰呀),/usr/bin/ld: cannot find -lclntsh
這個錯誤以前在mac上裝cx_Oracle時候沒遇到,百度解決方案,得知是沒有找到lib下的libclntsh.so函數庫
實際上是有的,只不過名字改了,加軟連接:
ln -s libclntsh.so.11.1 libclntsh.so
再次安裝解決。
補充:
非root安裝rpm包
首先把RPM包解壓出來,而後放在本身的目錄下,而且添加好環境變量
解壓的命令爲:rpm2cpio ctags-5.8-2.el6.x86_64.rpm | cpio -idvm
這樣就會按包裏的目錄結構解壓到當前目錄,若是是家目錄的話,能夠在家目錄下的.bashrc這樣添加環境變量
vim ~/.bashrc
export PATH=$PATH:$HOME/usr/bin/
從新登陸或者source ~/.bashrc
文件,就可使用這個程序了
easy_install --prefix=~/.local cx_Oracle
卸載:
python setup.py install --record record.txt --prefix=~/.local
而後刪除record.txt
裏的全部文件
貼段cx_Oracle 使用代碼,做爲備忘:
import cx_Oracle class ConnectOracle: def __init__(self, username, passwd, locate): self.login = {} self.db = None self.cursor = None self.login['username'] = username self.login['passwd'] = passwd self.login['locate'] = locate def connect_oracle(self): try: self.db = cx_Oracle.connect(self.login['username'], self.login['passwd'], self.login['locate']) # 登陸內搜數據庫 self.db.autocommit = False # 關閉自動提交 self.cursor = self.db.cursor() # 設置cursor光標 return True except: print 'can not connect oracle' return False def close_oracle(self): self.cursor.close() self.db.close() def select_oracle(self, sql, num=0, temp=None): if self.connect_oracle(): if temp: self.cursor.executemany(sql, temp) else: self.cursor.execute(sql) if num: content = self.cursor.fetchmany(num) else: content = self.cursor.fetchall() self.close_oracle() return content return False def insert_oracle(self, sql, temp=None): try: self.connect_oracle() if temp: self.cursor.executemany(sql, temp) # 執行多條sql命令 else: self.cursor.execute(sql) except: print "insert異常" self.db.rollback() # 回滾 finally: self.db.commit() self.close_oracle()
二 安裝mysql的操做模型:MySQLdb
先安裝依賴程序:yum install python-devel mysql-devel zlib-devel openssl-devel
三 安裝mysql的操做模型:Tornado
Tornado是非阻塞的開源的web服務器
下載安裝地址http://www.tornadoweb.cn/
tar xvzf tornado-1.2.1.tar.gz cd tornado-1.2.1 python setup.py build sudo python setup.py install
四, ipython
IPYTHON=1 ./bin/pyspark
IPYTHON_OPTS="notebook" ./bin/pyspark