linux下升级python版本
centos7.2自带的python版本为2.7.5
下载最新版本的python包:
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
解压压缩包
tar xvf Python-2.7.15.tgz
指定安装路径
cd Python-2.7.15 ./configure --prefix=/usr/local/python2.7
编译并安装
make make install
删除原指向链接,并重新链接
rm -f /usr/bin/python ln -s /usr/local/python2.7/bin/python /usr/bin/python
python升级成功
当删除原链接后,因为yum依赖python,yum将不能使用,此处我们先修复yum。
vi /usr/bin/yum #!/usr/bin/python ---> #!/usr/bin/python2.7 vi /usr/libexec/urlgrabber-ext-down #!/usr/bin/python ---> #!/usr/bin/python2.7
官网下载pip和setuptools
wget https://files.pythonhosted.org/packages/a6/5b/f399fcffb9128d642387133dc3aa9bb81f127b949cd4d9f63e5602ad1d71/ setuptools-39.1.0.zip wget https://files.pythonhosted.org/packages/ae/e8/2340d46ecadb1692a1e455f13f75e596d4eab3d11a57446f08259dee8f02/ pip-10.0.1.tar.gz
解压压缩包
tar xvf pip-10.0.1.tar.gz unzip setuptools-39.1.0.zip
安装setuptools
cd setup-tools-39.1.0 python setup.py install
如果没有zlib包会报错:
yum -y install zlib zlib-devel cd Python-2.7.15 make clean make sudo make install
安装成功后重新执行
cd setup-tools-39.1.0 python setup.py install
安装pip
cd pip-10.0.1 python setup.py install
创建pip软链
ln -s /usr/local/python2.7/bin/pip /usr/bin/pip pip
至此python和pip升级成功。
python学习网,免费的在线学习python平台,欢迎关注!