python2.6.6升级python2.7.14

Centos 6.8系统镜像默认安装的 python 环境是 2.6.6,线上需求需要升级到 2.7.14 版本,网上找了相关资料,升级 python 版本比较容易,但 yum/pip 等命令的使用也会有问题,网上的资料是修改脚本 #!/usr/bin/python 的头文件,个人感觉麻烦,还是直接升级比较好,不用修改任何系统脚本。

一、环境下载

// 下载python2.7.14并安装
# wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
# tar zxvf Python-2.7.14.tgz
# cd Python-2.7.14
# ./configure
# make
# make install

// 验证
# which python
/usr/local/bin/python

# python -V
Python 2.7.14

安装过程出现了个小插曲,执行which python命令是指向 /usr/local/bin/python 地址的,但执行python进入的确是2.6.6老版本,此时执行 source /etc/profile 生效环境变量,python即可进入正确的环境

二、pip安装升级

安装urllib3报错,提示pip版本使用python2.6版本过低,不能安装。

# pip install urllib3
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Requirement already satisfied: urllib3 in /usr/lib/python2.6/site-packages
You are using pip version 9.0.1, however version 19.2.2 is available.
You should consider upgrading via the ‘pip install --upgrade pip‘ command.

查看pip启动源码,发下脚本头部 #!/usr/bin/python 是使用系统自带的python命令。

# cat /usr/bin/pip
#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import main

if __name__ == ‘__main__‘:
    sys.argv[0] = re.sub(r‘(-script\.pyw|\.exe)?$‘, ‘‘, sys.argv[0])
    sys.exit(main())

通过下面可以看出pip还是使用系统的命令,对应的python版本是2.6.6,加载的packages也是2.6.6的,所以无法安装urllib3。

# which python
/usr/local/bin/python

# which pip
/usr/bin/pip

# pip --version
pip 9.0.1 from /usr/lib/python2.6/site-packages (python 2.6)

网上的一些资料是将头部 #!/usr/bin/python 直接软链到 python2.7,对于pip可行,但yum之类的其他命令会失效,行之有效的办法是直接在python2.7目录下生效pip命令。

使用如下方式生效python2.7中的pip命令:

# which python    //python使用的是2.7.14
/usr/local/bin/python

# python -m pip    //pip在python2.7.14找不到
/usr/local/bin/python: No module named pip

其中,-m参数的解释:run library module as a script (terminates option list)

#  python -m ensurepip  # 生效pip命令
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0

# python -m pip   //pip生效了,根据帮助文档使用
Usage:
  /usr/local/bin/python -m pip <command> [options]

# pip -V   //pip能正常加载python2.7的packages了
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

# pip install urllib3     #urllib3包也能正常安装了
Requirement already satisfied: urllib3 in /usr/local/lib/python2.7/site-packages
You are using pip version 9.0.1, however version 19.2.2 is available.
You should consider upgrading via the ‘pip install --upgrade pip‘ command.

其他基于python2.6.6版本的命令升级到python2.7.14方法一致。

结束时,顺便讲一下pip版本的升级与降级。查看网上资料时,有文章说 python -m ensurepip 后直接升级即可使用pip。

# python -m pip install --upgrade pip
# pip -V
pip 19.2.2 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

后来发现pip其实没必要升级,于是考虑降级到默认版本,使用如下方式降级即可。

# python -m pip install pip==9.0.1     //降级到指定版本
# pip -V     //降级成功
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

【参考资料】

原文地址:https://www.cnblogs.com/walker-/p/11605339.html

时间: 2024-10-28 04:04:22

python2.6.6升级python2.7.14的相关文章

python2.7.5升级到2.7.14或者直接升级到3.6.4

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.解

Centos——升级Python2.7及安装pip

CentOS升级Python2.7及安装pip 1) 升级Python2.7 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 python -V  # 查看版本:Python 2.6.6 mkdir -p ~/Env/python; cd ~/Env/python  # 创建个目录 wget --no-check-certificate https://www.pyt

CentOS升级Python2.7及安装pip

body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI",Tahoma,Helvetica,Sans-Serif,"Microsoft YaHei", Georgia,Helvetica,Arial,sans-serif,宋体, PMingLiU,serif; font-size: 10.5pt; line-height: 1.5;

升级python2.6.6到python2.7导致pip命令不可用

服务器环境为Centos6.8,python为默认的2.6.6版本 1.升级python python2.6.6 升级到python2.7.14,此处不再描述可以参考如下文档升级:https://blog.csdn.net/see_you_see_me/article/details/78550977 2.Python导致pip命令不可用 升级Python2.7导致使用pip等命令安装模块失败,报错如下: #pip Traceback (most recent call last): File

centos 7 python2.7.5升级到3.5.2

centos 7 python2.7.5升级到3.5.2 系统 centos 7 软件包 python3.5.2    下载:wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz 查看原有原有软件包 [[email protected] ~]# python  -V Python 2.7.5 创建Python-3.5.2的安装目录 [[email protected] ~]# mkdir /usr/local/python3.

centos yum 升级Python2.6 到 2.7

背景: 开发部需要使用python2.7,由于公网的环境python版本都是系统自带的,版本是2.6,需要升级,最好是通过RPM升级. 实施步骤: 1,下载nux 的release文件 wget http://li.nux.ro/download/nux/dextop/el6/i386/nux-dextop-release-0-2.el6.nux.noarch.rpm rpm -ivh nux-dextop-release-0-2.el6.nux.noarch.rpm yum -y instal

linux下升级python2.0到python3.0

升级python cd /home/sanlang/tools wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz  gunzip  Python-2.7.6.tgz  tar  xf Python-2.7.6.tar  cd Python-2.7.6  mkdir   -p  /application/python2.7.6  ./configure  --prefix=/application/python2.7.6 --

技巧方法 - CentOS6将Python2.6.6升级到Python2.7.6

1.首先使用"python -V"命令查看python版本,我们测试主机显示的是2.6.6版,于是下面就着手将python2.6.6升级到Python2.7.6.python -V #查看python版本2.接下来先请完成系统升级及安装开发工具包及相关需要的组件.只需执行下面三个命令完成安装即可.yum -y updateyum groupinstall "Development tools" -yyum install zlib-devel bzip2-devel

CentOS6系升级Python2.7的版本

安装前准备 本实例以centos6.7为例 [[email protected] tools]# uname -r 2.6.32-431.23.3.el6.x86_64 [[email protected] tools]# uname -m x86_64 [[email protected] ~]# python -V Python 2.6.6 内核版本2.6.32 64位操作系统 安装前先装readline-devel,不装"上下左右建"等无法使用 yum -y install re