在CentOS 5.3源码安装Python 2.7及模块

      最近需要在服务器上建立一个Python环境,第一次做,故做些记录.

      服务器采用的系统为CentOS release 5.3 (Final),采用源码安装Python 2.7.3.


      1.Python

      软件包版本: Python-2.7.3

      下载地址: http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2


      安装过程:

      a.将软件包至于合适的目录解包.

      此处在/usr/local/src中操作.执行命令:

tar -xjf Python-2.7.3.tar.bz2
 

      b.配置,编译与安装

      安装过程中没有做特别的要求,所以简单执行如下的命令:

./configure
make
make install

       至此,完成Python安装.


      2.安装setuptools和easy_install

      a.获取脚本ez_setup.py.此脚本将帮助获取setuptools的最新版本,并自动安装easy_install.

      执行:

curl http://peak.telecommunity.com/dist/ez_setup.py > ez_setup.py

 

      b.运行脚本ez_setup.py.需要注意的是,运行此脚本时要确定一起工作的Python版本,必要时直接指明是哪个版本.

      执行:

python ez_setup.py

      得到类似下面的输出:

Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /usr/local/lib/python2.7/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin

Installed /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

 

      此时,查看下目录/usr/local/bin,会见到下面两个文件:

       /usr/local/bin/easy_install

       /usr/local/bin/easy_install-2.7

 

      3.安装几个模块

      下面安装几个需要的模块,包括: jianfan, mysql-python.

      安装jianfan,执行:

easy_install jianfan

       得到类似输出:

Searching for jianfan
Reading http://pypi.python.org/simple/jianfan/
Reading http://code.google.com/p/python-jianfan/
Best match: jianfan 0.0.1
Downloading http://python-jianfan.googlecode.com/files/jianfan-0.0.1.tar.gz
Processing jianfan-0.0.1.tar.gz
Running jianfan-0.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-hLd3H5/jianfan-0.0.1/egg-dist-tmp-vtBk1J
zip_safe flag not set; analyzing archive contents...
Adding jianfan 0.0.1 to easy-install.pth file

Installed /usr/local/lib/python2.7/site-packages/jianfan-0.0.1-py2.7.egg
Processing dependencies for jianfan
Finished processing dependencies for jianfan

 

      安装mysql-python,执行:

easy_install mysql-python

       得到类似输出:

Searching for mysql-python
Reading http://pypi.python.org/simple/mysql-python/
Reading http://sourceforge.net/projects/mysql-python/
Reading http://sourceforge.net/projects/mysql-python
Best match: MySQL-python 1.2.4c1
Downloading http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.4c1.zip#md5=a05925412cd824104da064db6a889613
Processing MySQL-python-1.2.4c1.zip
Running MySQL-python-1.2.4c1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/egg-dist-tmp-1vXEb1
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Extracting in /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/temp/tmp_Z0Yyi
Now working in /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/temp/tmp_Z0Yyi/distribute-0.6.28
Building a Distribute egg in /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1
/tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/distribute-0.6.28-py2.7.egg
In file included from /usr/include/mysql/my_config.h:16,
                 from _mysql.c:44:
/usr/include/mysql/my_config_i386.h:1053:1: warning: "HAVE_WCSCOLL" redefined
In file included from /usr/local/include/python2.7/Python.h:8,
                 from _mysql.c:29:
/usr/local/include/python2.7/pyconfig.h:890:1: warning: this is the location of the previous definition
zip_safe flag not set; analyzing archive contents...
Adding MySQL-python 1.2.4c1 to easy-install.pth file

Installed /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.4c1-py2.7-linux-i686.egg
Processing dependencies for mysql-python
Finished processing dependencies for mysql-python

 

      在安装mysql-python,可能会遇到系统缺少和MySQL相关的必要包;此时可以使用yum进行安装.

         执行:

yum install mysql-devel

 

      验证看看刚才的两个模块是否已安装成功,进入python,使用import试试.比如在python交互式shell中,执行:

      import MySQLdb

      如果没有报错,则说明安装已成功.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值