[Switch] centos upgrade python2.6 to 2.7

Verified, original address: http://ruiaylin.github.io/2014/12/12/python%20update/

 

PS: How to build a blog on github

 

Install Python 2.7.X on CentOS 6.X

The python version that comes with CentOS 6.X is 2.6. Due to work needs, version 2.7 is often required. So a version upgrade is required. Since some system tools and services are dependent on Python, you need to pay attention to upgrading the Python version.

Upgrade steps

How to have a joyful, painless upgrade of python versions, see below...

Update system and development toolset

update instruction

yum -y update
yum groupinstall -y 'development tools'

Also need to install additional packages SSL, bz2, zlib required by python tools

yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget

Install Python 2.7.x from source

wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
xz -d Python-2.7.8.tar.xz
tar -xvf Python-2.7.8.tar

Installation details:

# 进入目录:
cd Python-2.7.8
# 运行配置 configure:
./configure --prefix=/usr/local
# 编译安装:
make
make altinstall
# 检查 Python 版本:
[root@dbmasterxxx ~]# python2.7 -V
Python 2.7.8

set PATH

In order for us to use Python conveniently, we need to set system variables or establish a soft connection to add the new version of Python
to the directory corresponding to the path:

export PATH="/usr/local/bin:$PATH"
or 
ln -s /usr/local/bin/python2.7  /usr/bin/python
# 检查
[root@dbmasterxxx ~]# python -V
Python 2.7.8
[root@dbmasterxxx ~]# which python 
/usr/bin/python

Install setuptools

#获取软件包
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz
# 解压:
tar -xvf setuptools-1.4.2.tar.gz
cd setuptools-1.4.2
# 使用 Python 2.7.8 安装 setuptools
python2.7 setup.py install

install pip

curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | python2.7 -

repair yum tool

At this point, yum should be invalid, because the default python version is already 2.7. And yum needs 2.6 so:

[root@dbmasterxxx ~]# which yum 
/usr/bin/yum
#修改 yum中的python 
将第一行  #!/usr/bin/python  改为 #!/usr/bin/python2.6
此时yum就ok啦

Summarize

Python 版本升级过很多遍,每次都有问题,此方法来自互联网,经过使用,没有问题,特此总结一下

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327037933&siteId=291194637