Centos python2.6 升级 python2.7

Centos python2.6 升级 python2.7

安装python2.7

  1. 下载python2.7源码,解压

    1
    2
    3
    wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
    tar xvf Python-2.7.13.tgz
    cd Python-2.7.13
  2. 安装,默认安装位置为/usr/local/bin/

    1
    2
    3
    ./configure
    make
    sudo make install
  3. 替换python2.6,建立python2.7软链接

    1
    2
    3
    4
    5
    cd /usr/local/bin/
    sudo ln -s /usr/local/python27/bin/python2.7 python2.7
    sudo ln -s /usr/local/python27/bin/python2.7-config python2.7-config
    sudo mv python python.back
    sudo ln -s python2.7 python

问题解决

  1. yum不支持python2.7,修改下,让其直接调用python2.6,如果有别的工具也不支持python2.7,方法相同

    1
    2
    sudo vim /usr/bin/yum
    将第一行#!/usr/bin/python 修改为#!/usr/bin/python2.6
  2. 为python2.7安装easy_install

    1
    2
    wget wget -q http://peak.telecommunity.com/dist/ez_setup.py
    sudo python ez_setup.py -U setuptools
  3. 为python2.7安装pip,在https://pypi.python.org/pypi/pip/9.0.1 下载pip源码

    1
    2
    3
    4
    5
    6
    7
    8
    tar zxvf pip-9.0.1.tar.gz
    cd pip-9.0.1
    python setup.py build
    sudo python setup.py install
    sudo ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip2.7
    cd /usr/bin/
    sudo mv pip pip.back
    sudo ln -s pip2.7 pip
  4. python2.7命令行不可用

    1
    sudo pip install readline