Fork me on GitHub
Suzf  Blog

Python 版本升级shell简略版

License: Attribution-NonCommercial-ShareAlike 4.0 International

本文出自 Suzf Blog。 如未注明,均为 SUZF.NET 原创。

转载请注明:http://suzf.net/post/360

尽管Python3很早之前就出现了但是现在很多企业用的还是2.7居多 天朝系统版本CentOS居多 故以CentOS6为实验环境 Python 从 2.6 升级到 2.7 OoO
#!/bin/bash
# Desc: Python && pip upgrade
# Author: Jeffrey.su
# Mail: [email protected]
# Date:  Oct 09, 2014
# Home: http://suzf.net

DOWN_PATH=/usr/local/src
PY_VERSION=2.7.3
PY_BIN_NAME=python2.7
PY_OLD_VERSION=`python -V 2>&1 | awk '{print $2}'`


function prepare_work(){

  yum -y install zlib  openssl openssl-devel curl wget gcc patch ncurses-devel
  # yum install ipython 

}

function python_upgrade(){

  cd ${DOWN_PATH}
  wget -c https://www.python.org/ftp/python/${PY_VERSION}/Python-${PY_VERSION}.tgz
  tar zxf Python-${PY_VERSION}.tgz
  cd Python-${PY_VERSION}
  ./configure --prefix=/usr/local/Python${PY_VERSION} --enable-shared
  make && make install
  mv /usr/bin/python /usr/bin/python_${PY_OLD_VERSION}
  cp /usr/bin/yum{,.old} && sed -i s/python/python${PY_OLD_VERSION}/ /usr/bin/yum

  ln -s /usr/local/Python${PY_VERSION}/bin/${PY_BIN_NAME} /usr/bin/python

}

function pip_upgrade(){

  cd ${DOWN_PATH}
  curl -O https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
  tar zxf setuptools-2.0.tar.gz
  cd setuptools-2.0
  python setup.py build && python setup.py install


  cd ${DOWN_PATH}
  curl -O https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
  tar zxf pip-7.1.2.tar.gz     
  cd pip-7.1.2    
  python setup.py install
  mv /usr/bin/pip{,.old}  && ln -s /usr/local/Python${PY_VERSION}/bin/pip /usr/bin/pip
  pip install readline
}

 
prepare_work
python_upgrade
pip_upgrade

 

「一键投喂 软糖/蛋糕/布丁/牛奶/冰阔乐!」

Suzf Blog

(๑>ڡ<)☆ 谢谢 ~

使用微信扫描二维码完成支付