centos升级python到2.7.13

centos升级python到2.7.13

  • 升级python
  • 升级pip

升级python

wget wget http://python.org/ftp/python/2.7.13/Python-2.7.13.tg
tar -xvf Python-2.7.13.tgz
cd Python-2.7.13

#创建新的文件夹防止覆盖原版
mkdir /usr/local/python2713
./configure --prefix=/usr/local/python2713
make

make 结束后会提示有些包需要单独安装

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter        
bsddb185           bz2                dbm             
dl                 gdbm               imageop         
readline           sunaudiodev   

以_sqlite3为例子

yum install sqlite-devel

重新编译python

make
#可以发现_sqlite3已经不在提示种,表面已经编译,然后安装
make install

备份旧版本python,因为升级后yum无法使用

mv /usr/bin/python  /usr/bin/python_old
ln -s /usr/local/python2713/bin/python2.7 /usr/bin/python

修改/usr/bin/yum 和 /usr/libexec/urlgrabber-ext-down
头改为 #!/usr/bin/python_old

升级pip

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
rm -rf /usr/bin/pip
ln -s /usr/local/python2713/bin/pip2.7 /usr/bin/pip

pip -V查看版本确定升级完成

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