CentOS 6升级Python 2.7.12并安装最新pip过程记录

1.94K 阅读技术资料CentOS 6 Python Python升级
0

因为好久以前启用的是CentOS 6,默认的是Python2.6.6版本,现在不少的软件需要2.7以上的,特此记录一下Python2.6.6升级到Python 2.7.12的全过程:

#下载源码
wget http://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
 #在下载目录解压源码
tar -zxvf Python-2.7.12.tgz
 #进入解压后的文件夹
cd Python-2.7.12
 #在编译前先在/usr/local建一个文件夹python2.7.12(作为python的安装路径,以免覆盖老的版本,新旧版本可以共存的)
mkdir /usr/local/python2.7.12
 #编译前需要安装下面依赖,否则下面安装pip就会出错
yum install openssl openssl-devel zlib-devel gcc -y
 #安装完依赖后执行下面命令
vim ./Modules/Setup.dist
 #找到#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz去掉注释并保存(即去掉井号),vim的搜索命令是输入/,再输入关键字回车
 #在解压缩后的目录下编译安装
./configure --prefix=/usr/local/python2.7.12 --with-zlib
make
make install
 #此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
mv /usr/bin/python /usr/bin/python2.6.6
 #建立新版本python的软链接
ln -s /usr/local/python2.7.12/bin/python2.7 /usr/bin/python
 #输入
python
 #显示出python的新版本信息
[root@ping Python-2.7.12]# python
Python 2.7.12 (default, Sep 22 2019, 08:15:45) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
    #修改yum配置文件
#之所以要保留旧版本,因为yum依赖Python2.6,改下yum的配置文件,指定旧的Python版本就可以了。
 vim /usr/bin/yum
 #将第一行的#!/usr/bin/python修改成#!/usr/bin/python2.6.6
    #安装最新版本的pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
 #此步如果出现以下错误:
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
  ERROR: Could not find a version that satisfies the requirement pip (from versions: none)
ERROR: No matching distribution found for pip
 #尝试用以下方法
#yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
#yum install readline-devel sqlite-devel bzip2-devel.i686 openssl-devel.i686 gdbm-devel.i686 libdbi-devel.i686 ncurses-libs,zlib-devel.i686
 #curl https://bootstrap.pypa.io/get-pip.py | python 
 #找到pip2.7的路径,此步可以省略,一般来是在/usr/local/python2.7.12/bin/pip2.7
find / -name "pip*"
 #为其创建软链作为系统默认的启动版本(之前有旧版本的话就先删掉rm -rf /usr/bin/pip)
ln -s /usr/local/python2.7.12/bin/pip2.7 /usr/bin/pip
 #看一下pip的版本
pip -V

分享到:
提问于

Login

Welcome! Login in to your account

Remember meLost your password?

Don't have account. Register

Lost Password

Register