备忘 - centos5.6 安装 python 2.7

本文介绍如何将CentOS 5.6系统的Python版本从2.4升级到2.7,并安装一系列常用Python模块如setuptools、feedparser等。同时提供了处理升级后yum工具无法使用的问题的方法。

centos 5.6 自带的python版本为2.4,太旧了。

1. install python 2.7

  refer: http://www.cnblogs.com/minglog/archive/2011/04/20/2022479.html

 

  wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2

  ./configure 

  make

  make install

 

  rm /usr/bin/python

  ln -s /usr/local/bin/python2.7 /usr/bin/python 

 

  *******************

  发现yum不能用了,yum依赖python2.4, 处理如下:

  vim /usr/bin/yum

将文件头部的

#!/usr/bin/python

改成

#!/usr/bin/python2.4

就可以继续使用yum了

*******************

 2. install setuptools

  wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea

 

  sh setuptools-0.6c11-py2.7.egg

 

 3. install python modules

  .feedparser

  #easy_install feedparser 编码处理有些问题

  下载feedparser-5.0.1源码

  feedparser.py 3524行

 

  elif http_content_type.startswith('text/'):

        #true_encoding = http_encoding or 'us-ascii'

        true_encoding = http_encoding or xml_encoding or 'utf-8'

    

  python setup.py build

        python setup.py install

        

        .BeautifulSoup    

  easy_install BeautifulSoup


        .chardet

  easy_install chardet

 

  .PIL

  yum install libjpeg-devel zlib-devel freetype-devel

  #easy_install PIL #has problems, not support jpeg, etc

  wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz

  python setup.py build_ext -i

  python setup.py install

 

  .MySQLdb

  yum install mysql-devel

  http://ncu.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz

  python setup.py build

  python setup.py install


4. Tips

easy_install安装后如何删除

编辑 /usr/local/lib/python2.7/site-packages/easy-install.pth , 删除相应的行。删除相应的egg文件。


python -u

-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'


### 在线安装 Python 2.7 的步骤 在 CentOS 系统上在线安装 Python 2.7,可以通过系统的包管理器 `yum` 来完成。以下是一系列详细的步骤: 1. **更新系统软件包** 在安装新软件之前,确保系统上的软件包列表是最新的: ```bash sudo yum update -y ``` 2. **安装 EPEL 仓库** CentOS 默认仓库中可能没有 Python 2.7 的相关包,因此需要先安装 EPEL(Extra Packages for Enterprise Linux)仓库: ```bash sudo yum install epel-release -y ``` 3. **安装 Python 2.7** 安装 Python 2.7 可以通过以下命令完成: ```bash sudo yum install python27 -y ``` 4. **验证安装** 安装完成后,可以通过以下命令验证 Python 是否安装成功: ```bash python2.7 --version ``` 如果安装成功,将显示 Python 2.7 的版本信息。 5. **设置默认 Python 版本(可选)** 如果系统中存在多个 Python 版本,可以通过以下命令设置默认的 Python 版本为 2.7: ```bash sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --config python ``` 在提示中选择 Python 2.7 的选项。 6. **安装 pip(可选)** 如果需要安装 `pip` 工具来管理 Python 包,可以运行以下命令: ```bash sudo yum install python-pip -y ``` 安装完成后,可以通过以下命令验证 `pip` 是否安装成功: ```bash pip --version ``` ### 注意事项 - **依赖关系**:某些系统工具或服务可能依赖于默认的 Python 版本(如 Python 2.6)。在更改默认 Python 版本时,请确保不会影响到这些依赖项。 - **兼容性**:如果系统中已有其他版本的 Python 并且需要与 Python 2.7 共存,建议不要修改默认的 Python 版本,而是通过指定完整路径来使用特定版本的 Python- **安全性**:Python 2.7 已于 2020 年停止官方支持,因此在生产环境中使用时需要注意潜在的安全风险。 ###
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值