VPS 的 CentOS6 升级 Python 的方法

VPS 的 CentOS6 升级 Python 的方法

centos默认安装python2.6。由于python和centos关联紧密,所以不建议卸载,进行编译升级

1.新开的VPS务必系统更新


yum -y update
yum groupinstall -y development or; yum groupinstall -y ‘development tools’
yum install -y zlib-dev zlib-devel  openssl-devel sqlite-devel bzip2-devel xz-libs
2.升级python>=2.7
编译参看: https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
wget http://www.python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz
xz -d Python-2.7.6.tar.xz
tar -xvf Python-2.7.6.tar
xz -d Python-3.3.3.tar.xz
tar -xvf Python-3.3.3.tar
# Enter the file directory:
cd Python-2.7.6
# Start the configuration (setting the installation directory)
# By default files are installed in /usr/local.
# You can modify the –prefix to modify it (e.g. for $HOME).
./configure –prefix=/usr/local  
cd Python-3.3.3    
./configure
为了不覆盖系统默认选项 – 替换系统正在使用的PYTHON- 我们使用 make altinstall.
# Let’s build (compile) the source
# This procedure can take awhile (~a few minutes)
make
# After building everything:
make altinstall
    Example for version 3.3.3:
make && make altinstall   # <— Two commands joint together
我们直接进行
make
make install
3.建立软连接
编译的软件安装于 /usr/local/bin/python2.7
所以需要替换原来的 /usr/bin/python
mv /usr/bin/python /usr/bin/python2.6
rm /usr/bin/python
ln -s /usr/local/bin/python2.7 /usr/bin/python
vim /usr/bin/yum
/usr/bin/python 改成 /usr/bin/python2.6
4.更新 pip
https://bootstrap.pypa.io/get-pip.py
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
ln -s /usr/local/bin/pip /usr/bin/pip
如果wget下载不了这文件,可能是DNS解析问题,需要下载个文件
vi /etc/resolv.conf
nameserver 8.8.4.4
nameserver 8.8.8.8

原文链接:,转发请注明来源!

发表评论