在Linux (ubuntu)上安装配置MySQLdb,cx_Oracle,PIL,JSON,Config 等Python模块

Saturday, January 30, 2010

今天把server上的一些cron作业的python脚本迁移到另一台server上(server都是ubuntu),所以要配置下python环境,我的python脚本用到了MySQLdb,cx_Oracle,PIL,JSON,Config
等几个Python扩展模块!

1、安装PIL 模块

The Python Imaging Library
(PIL)
adds image processing
capabilities to your Python interpreter. This library supports many file
formats, and provides powerful image processing and graphics
capabilities.

在linux中可以直接apt-get:

sudo apt-get install python-imaging

2、安装MySQLdb模块

sudo apt-get install python-mysqldb

3、安装JSON模块

sudo cp /home/lxneng/python_module/json.py /usr/lib/python2.5/

4、安装config模块
A hierarchical, easy-to-use, powerful configuration module for Python

wget http://www.red-dove.com/config-0.3.7.tar.gz
sudo tar zxvf config-0.3.7.tar.gz
cd config-0.3.7/
sudo python setup.py install

5、安装Oracle XE客户端 和 cx_Oracle 模块(挺麻烦的

 sudo apt-get install libc6-dev
 sudo dpkg -i oracle-xe-client_10.2.0.1-1.2_i386.deb
 sudo editor /etc/ld.so.conf 在最后一行加入
 /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib

然后执行

sudo ldconfig

设置环境

 sudo editor /etc/profile
 export
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client
 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
 export TNS_ADMIN=/usr/lib/oracle
 export PATH=$PATH:$ORACLE_HOME/bin
 sudo dpkg -i cx-oracle_5.0.1-2_i386.deb

—————-安装完成—————————–
测试代码

>>> import os
>>> import cx_Oracle
>>> os.environ['NLS_LANG']=”SIMPLIFIED CHINESE_CHINA.ZHS16GBK”
#这句话是为了让oracle database中读出来的gbk编码中文正常显示而设设置的语言环境
>>> dsn = cx_Oracle.makedsn(“192.168.1.10″, “1521″, “db”)
>>> conn = cx_Oracle.connect(username, password, dsn)
>>> db_cursor = conn.cursor()
>>> db_cursor.execute(“select ID from HEJIA_COMPANY where
rownum<6″)

>>> rows = db_cursor.fetchall()
>>> for row in rows:
… print row[0]
…
39
470
453
1020
1362
>>>

This entry was tagged Django, Linux, MySQL, Oracle and Python

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top