美文网首页
centos7 python2和python3版本共存

centos7 python2和python3版本共存

作者: _fishman | 来源:发表于2020-04-24 17:28 被阅读0次
    安装Python 3.6和pip
    [root@iZbp118g1g7ag3ud75297fZ ~]# yum install -y python36 python36-setuptools
    
    update-alternatives分别安装两个版本的python和pip
    
    [root@iZbp118g1g7ag3ud75297fZ ~]# alternatives --install /usr/bin/python python /usr/bin/python2.7 1
    [root@iZbp118g1g7ag3ud75297fZ ~]# alternatives --install /usr/bin/python python /usr/bin/python3.6 2
    [root@iZbp118g1g7ag3ud75297fZ ~]# mv /usr/bin/pip /usr/bin/pip.bak    # 原有的pip不是软连接,先把它干掉
    [root@iZbp118g1g7ag3ud75297fZ ~]# alternatives --install /usr/bin/pip pip /usr/bin/pip2.7 1
    [root@iZbp118g1g7ag3ud75297fZ ~]# alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.6 2
    
    检查一下设置是否生效
    [root@iZbp118g1g7ag3ud75297fZ ~]# alternatives --display python
    python - status is manual.
     link currently points to /usr/bin/python3.6
    /usr/bin/python3.6 - priority 2
    /usr/bin/python2.7 - priority 1
    Current `best' version is /usr/bin/python3.6.
    
    切换python和pip版本
    [root@iZbp118g1g7ag3ud75297fZ ~]# alternatives --config python
    
    There are 2 programs which provide 'python'.
    
      Selection    Command
    -----------------------------------------------
    *+ 1           /usr/bin/python3.6
       2           /usr/bin/python2.7
    
    Enter to keep the current selection[+], or type selection number: 1  #输入对应版本的序号
    
    后续yum问题
    vi /usr/bin/yum
    首行的#! /usr/bin/python
    都改为#! /usr/bin/python2.7
    
    firewall-cmd也需要手工设置一下
    
    # vim /usr/bin/firewall-cmd
     
    首行改为
    #!/usr/bin/python2.7 -Es
    
    安装python包
    需要将python切换到3.6以后再执行
    python -m pip install xmind2testcase
    

    参考:https://blog.csdn.net/lpwmm/article/details/80160242

    相关文章

      网友评论

          本文标题:centos7 python2和python3版本共存

          本文链接:https://www.haomeiwen.com/subject/ugzfwhtx.html