Linux下将python2.6升级到2.7 安装pip 以及升级中遇到问题的解决方法

python2.6版本有很多局限性:最重要的就是,当前最新的pip版本已经不再支持python2.6;这给我们安装很多python库增加了很多不便;所以这里把我升级python2.6--2.7的过程及遇到的坑 记录一下:

实验系统版本centos6+ ;centos7+版本自带的python版本就是2.7+的。

第一步:安装相关的编译依赖包:

[root@lexsaints ~]# yum install -y gcc
[root@lexsaints ~]# yum install openssl-devel zlib-devel readline-devel sqlite-devel -y
第二步:到自己的目录下:下载 解压 编译配置
[root@lexsaints ~]# cd /opt/python/
[root@lexsaints ~]# wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
[root@lexsaints ~]# tar -vxf Python-2.7.10.tar
[root@lexsaints ~]# cd Python-2.7.10
[root@lexsaints Python-2.7.10]# ./configure --enable-shared --enable-loadable-sqlite-extensions \ --prefix=/usr/local/python27 --with-zlib --with-ssl
[root@lexsaints Python-2.7.10]# vim ./Modules/Setup
# 打开这句注释#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

第三步:执行编译安装

[root@lexsaints Python-2.7.10]#make && make install

出现的问题:安装过程中:出现编译问题:一般都是本机的编译器gcc等没有安装导致的;执行第一步的依赖包安装;再进行编译安装就不会有问题了

第四步:python相关配置

此时安装完成之后:我们查看版本还是2.6,需要修改配置, 用 python2.7 替换旧版本
[root@lexsaints Python-2.7.10]# cd /usr/bin/
[root@lexsaints bin]# ls python* -l # 旧 python 版本信息
-rwxr-xr-x. 2 root root 4864 2月 22 2013 python
lrwxrwxrwx. 1 root root 6 10月 22 18:38 python2 -> python
-rwxr-xr-x. 2 root root 4864 2月 22 2013 python2.6
[root@lexsaints bin]# mv /usr/bin/python /usr/bin/python2.6.6
[root@lexsaints bin]# ln -s /usr/local/python27/bin/python2.7 /usr/bin/python
第五步:配置及yum出现问题的解决
[root@ lexsaints ~]# vim /etc/ld.so.conf
# 添加如下一行内容/usr/local/python27/lib
[root@ lexsaints ~]# ldconfig # 使新添加的路径生效
然后 就可以了:python -V :2.7.10
另外:安装完之后:由于现有的yum需要依赖python2.6;而我们配置了python2.7之后;yum会自动使用2.7所以造成yum不可用的问题:
解决方法: 编辑 yum 配置文件
[root@ lexsaints bin]# vim /usr/bin/yum#!/usr/bin/python
# 第一行修改为 python2.6.6#!/usr/bin/python2.6.6


============python2.7升级完成===========

然后使用python -V查看版本

安装pip

[root@lexsaints~]# wget https://bootstrap.pypa.io/get-pip.py
[root@lexsaints~]# python get-pip.py
设置软连接
[root@ lexsaints~]# ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip
使用pip安装python库
[root@ lexsaints ~]#pip install requests


猜你喜欢

转载自blog.csdn.net/weixin_42350212/article/details/80556292