zoukankan      html  css  js  c++  java
  • Python2升级到Python3

    操作系统环境:CentOS Linux release 7.4.1708 (Core)。
    系统默认Python版本为2.7。

    升级前的版本信息:

    [root@cch-spider-web1 ~]# ll /usr/bin/python*
    lrwxrwxrwx. 1 root root    7 Oct 15  2017 /usr/bin/python -> python2
    lrwxrwxrwx. 1 root root    9 Oct 15  2017 /usr/bin/python2 -> python2.7
    -rwxr-xr-x. 1 root root 7136 Aug  4  2017 /usr/bin/python2.7
    

    安装Python3:

    yum install -y gcc gcc-c++ libffi-devel python-setuptools vim wget make sqlite-devel zlib*  bzip2-devel openssl-devel ncurses-devel readline-devel tk-devel
    cd /opt
    wget https://mirrors.huaweicloud.com/python/3.9.6/Python-3.9.6.tar.xz
    tar -zxvf Python-3.9.6.tar.xz
    cd /opt/Python-3.9.6
    ./configure --with-ssl
    make
    make install
    

    设置默认版本:

    mv /usr/bin/python /usr/bin/python.bak
    ln -s /usr/local/bin/python3 /usr/bin/python
    

    修复yum配置:

    修改/usr/bin/yum/usr/libexec/urlgrabber-ext-down,将#!/usr/bin/python改为#!/usr/bin/python2.7,保存退出即可。

    升级pip:

    pip3 install --upgrade pip
    

    解决root用户执行pip3命令时提示警告的问题:

    [root@cch-spider-web1 ~]# pip3 install --upgrade pip
    Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
    Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.1.3)
    WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
    

    改为执行时带上--user参数:

    pip3 install --user packagename
    

    至此,Python2升级到Python3完毕!

    【参考】
    https://www.cnblogs.com/cuianbing/p/13433528.html Centos7升级Python
    https://blog.csdn.net/weixin_43465312/article/details/105480343 centos7 中python pip3安装报警告提示Try pip3 install --user instead.


    作者:编程随笔
    出处:http://www.cnblogs.com/nuccch/
    声明:本文版权归作者和博客园共有,欢迎转载,但请在文章页面明显位置给出原文连接。

  • 相关阅读:
    flex>数据绑定、数据列表 小强斋
    上周问题总结与解决方案
    asp.net 实现无限级分类
    发个项目需求大家瞅瞅
    ASP.NET POST模拟登陆
    HttpWebRequest发送数据 post
    asp.net 生成静态页面
    xcode4.1自带SVN配置
    模拟登录
    C#中用HttpWebRequest/HttpWebResponse来发送/接收数据
  • 原文地址:https://www.cnblogs.com/nuccch/p/15153978.html
Copyright © 2011-2022 走看看