• Ubuntu 安装python3及多版本切换


    Ubuntu上python版本查看

    $ python -V
    Python 2.7.12

    1.安装3.7

    添加源

    sudo add-apt-repository ppa:deadsnakes/ppa

    检查更新

    sudo apt-get update 

    安装python3.7

    sudo apt-get install python3.7

    安装pip3

    sudo apt install python3-pip

    2.使用 update-alternatives 来为整个系统更改Python 版本

    查看python替代版本信息

    ~$ update-alternatives --display python

    但是结果为

    update-alternatives: error: no alternatives for python

    python的替代版本尚未被update-alternatives

    查看python的位置

    $ whereis python
    python: /usr/bin/python2.7 /usr/bin/python3.7 /usr/bin/python3.5m /usr/bin/python3.7m /usr/bin/python3.5 /usr/bin/python /usr/lib/python2.7 /usr/lib/python3.7 /usr/lib/python3.5 /etc/python2.7 /etc/python3.7 /etc/python3.5 /etc/python /usr/local/lib/python2.7 /usr/local/lib/python3.7 /usr/local/lib/python3.5 /usr/share/python /usr/share/man/man1/python.1.gz

    更新一下替代列表

    $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
    update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
    baby@ubuntu:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
    update-alternatives: using /usr/bin/python3.7 to provide /usr/bin/python (python) in auto mode

    查看python替代版本信息

    $ update-alternatives --display python                             python - auto mode
      link best version is /usr/bin/python3.7
      link currently points to /usr/bin/python3.7
      link python is /usr/bin/python
    /usr/bin/python2.7 - priority 1
    /usr/bin/python3.7 - priority 2

    查看python版本

    $ python -V
    Python 3.7.9

    3.切换版本

    切换到2.7

    $ sudo update-alternatives --config python
    There are 2 choices for the alternative python (providing /usr/bin/python).
    
      Selection    Path                Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/python3.7   2         auto mode
      1            /usr/bin/python2.7   1         manual mode
      2            /usr/bin/python3.7   2         manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 1
    update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode
    baby@ubuntu:~$ python -V
    Python 2.7.12

    pip版本

    $ pip -V
    pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

    切换到3.7

    sudo update-alternatives --config python
    There are 2 choices for the alternative python (providing /usr/bin/python).
    
      Selection    Path                Priority   Status
    ------------------------------------------------------------
      0            /usr/bin/python3.7   2         auto mode
    * 1            /usr/bin/python2.7   1         manual mode
      2            /usr/bin/python3.7   2         manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 2
    update-alternatives: using /usr/bin/python3.7 to provide /usr/bin/python (python) in manual mode
    baby@ubuntu:~$ python -V
    Python 3.7.9

    安装pip

    sudo apt install python3-pip

    pip版本

     pip -V
    pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.7)

    pip的版本随着python版本切换

  • 相关阅读:
    linux中断子系统
    注释规范
    linux下C获取文件的大小
    oracle 11g 修改内存示例
    联想system sr650安装windows
    iphone 手机音乐制作
    canon dpp 编辑相机raw软件
    浪潮nf5270m5 安装2012
    三种刻录工具及用法
    centos7.5 连接存储配置iscsi
  • 原文地址:https://www.cnblogs.com/baby123/p/14234171.html
Copyright © 2020-2023  润新知