centos 升级 python

USAGE:

1.请使用sudo权限执行:sudo ./upgrade_python.sh
2.如果yum使用的python和升级的版本不同,要修改/usr/bin/yum:
#/usr/bin/python 改成 #/usr/bin/python-2.6 (6U2版本的alios用python2.6,根据实际情修改)
3.虚拟环境配置,在~/.bashrc文件里添加如下代码:
source /usr/bin/virtualenvwrapper.sh
VENVS=~/.virtualenv
export PYTHON_DEPLOY=ONLINE

CODE:

#!/bin/sh
##############################################################################################################################

#record initial directory
CWD=`pwd`
PASSWORD=Lyy19890727

#do job
if [ ! -d "${CWD}/python" ]; then
mkdir ${CWD}/python
fi

cd ${CWD}/python

echo -e "\n\n"
echo "********************** upgrade python **************************"
echo -e "\n\n"

wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz --no-check-certificate
tar zxvf Python-2.7.11.tgz

wget "http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz" --no-check-certificate
tar zxvf setuptools-0.6c11.tar.gz

wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
tar zxvf pip-1.5.4.tar.gz

cd ${CWD}/python/Python-2.7.11
./configure --prefix=/usr/local/
make

make install
rm /usr/bin/python
rm /usr/bin/python-config
ln -s /usr/local/python27/bin/python2.7 /usr/bin/python
ln -s /usr/local/python27/bin/python2.7 /usr/bin/python2
ln -s /usr/local/python27/bin/python2.7-config /usr/bin/python-config
ln -s /usr/local/python27/bin/python2.7-config /usr/bin/python2-config

cd ${CWD}/python/setuptools-0.6c11

python setup.py build
python setup.py install

cd ${CWD}/python/pip-1.5.4

python setup.py install
pip install virtualenv
pip install virtualenvwrapper

#back to initial directory
cd ${CWD}
##############################################################################################################################


你可能感兴趣的:(centos 升级 python)