【问题标题】:How do I change my default python 3 having more than one version installed (Ubuntu 18.04)? [duplicate]如何更改安装了多个版本的默认 python 3 (Ubuntu 18.04)? [复制]
【发布时间】:2020-12-13 11:58:59
【问题描述】:

当我在终端中输入 python --version 时,它显示 Python 3.8.5,但当我输入 python3 --version 时,它显示 Python 3.6.9。我想使用python3 -m venv .venv 和3.8.5 版本创建一个虚拟环境,但是由于我的默认python3 版本是3.6.9,它使用3.6.9 作为它的版本来创建一个虚拟环境。如何更改我的默认 python3 版本?

【问题讨论】:

    标签: python linux ubuntu terminal


    【解决方案1】:

    pythonpython3 命令通常是指向实际可执行文件的软链接,您可以更改目标。例如:

    首先,找出python 3.6和python 3.8的位置:

    # which python
    /usr/bin/python
    # ls -l /usr/bin/python
    /usr/bin/python -> python3.8
    # which python3
    /usr/bin/python3
    # ls -l /usr/bin/python3
    /usr/bin/python3 -> python3.6
    

    然后,更改软链接:

    # rm /usr/bin/python3
    # ln -s /usr/bin/python3.8 /usr/bin/python3
    

    【讨论】:

      【解决方案2】:

      在终端中运行此命令

      sudo update-alternatives --config python
      

      你会得到选择提示,输入你想要的python版本的选择号。

      但如果显示如下错误:update-alternatives: error: no alternatives for python3

      然后你必须更新你的update-alternatives,然后你就可以设置你的默认python版本了。

      sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6.9
      sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8.5
      

      现在运行下面的命令来设置默认python

      sudo update-alternatives  --set python /usr/bin/python3.8
      

      【讨论】:

        猜你喜欢
        • 2020-05-25
        • 2016-02-27
        • 1970-01-01
        • 2021-03-12
        • 2020-11-30
        • 1970-01-01
        • 1970-01-01
        • 2022-11-20
        • 1970-01-01
        相关资源
        最近更新 更多