python2.7.5升级到2.7.14
1.安装升级GCC
yum install -y gcc* openssl openssl-devel ncurses-devel.x86_64 bzip2-devel sqlite-devel zlib python-devel mysql-devel openldap-devel
2.下载python安装包
wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
3.解压
tar -xvf Python-2.7.14.tar.xz
4.编译安装
cd Python-2.7.14
./configure --prefix=/usr/local
make && make install
5.将老版本python更换
mv /usr/bin/python /usr/bin/python2.7.5
6.更换默认python
ln -s /usr/local/bin/python2.7 /usr/bin/python
7.#修改 yum以及urlgrabber-ext-down中的python
将#!/usr/bin/python改为 #!/usr/bin/python2.7.5
vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down
8.安装setuptools
wget --no-check-certificate https://pypi.python.org/packages/69/56/f0f52281b5175e3d9ca8623dadbc3b684e66350ea9e0006736194b265e99/setuptools-38.2.4.zip#md5=e8e05d4f8162c9341e1089c80f742f64
unzip setuptools-38.2.4.zip
cd setuptools-38.2.4
python setup.py install
cd ..
9.安装pip
wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz
tar -xvf 1.5.5.tar.gz #解压文件
cd pip-1.5.5/
python setup.py install
python2.7.5升级到3.6.4
yum install -y gcc* openssl openssl-devel ncurses-devel.x86_64 bzip2-devel sqlite-devel zlib python-devel mysql-devel openldap-devel
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
tar -xvf Python-3.6.4.tar.xz
cd Python-3.6.4
mkdir -p /usr/local/python3
./configure --prefix=/usr/local/python3
make && make install
mv /usr/bin/python /usr/bin/python2.7.5
mv /usr/bin/pip /usr/bin/pip2.7
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip
查看版本
[[email protected] Python-3.6.4]# pip -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
[[email protected] Python-3.6.4]# python -V
Python 3.6.4
[[email protected] Python-3.6.4]# which python
/usr/bin/python
[[email protected] Python-3.6.4]# which pip
/usr/bin/pip
[[email protected] Python-3.6.4]#
#修改 yum以及urlgrabber-ext-down中的python
vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down
将#!/usr/bin/python改为 #!/usr/bin/python2.7.5
PS:python3.6.4是默认安装pip的,所以不需要另行安装setuptools和pip.
原文地址:https://www.cnblogs.com/sandshell/p/11757457.html