【问题标题】:How to make python3 command run Python 3.6 instead of 3.5?如何让 python3 命令运行 Python 3.6 而不是 3.5?
【发布时间】:2017-09-30 07:25:04
【问题描述】:

我刚刚下载了 Python 3.6.1,但是当我在终端中输入 python3 -V 时,它仍然是 Python 3.5.3。如何使python3 指向Python 3.6?所有版本都在/usr/bin/ 目录中。

【问题讨论】:

  • “下载”是什么意思?你“安装”了吗?怎么样?
  • sudo apt-get install python3.6

标签: python linux python-3.x ubuntu environment-variables


【解决方案1】:

rm /usr/bin/python3
ln -s /usr/bin/python3.6 /usr/bin/python3

更好的解决方案

该死,在 Ubuntu 的大部分系统脚本和软件中都使用 Python,而软件依赖于在特定位置使用 Python(以及启动 Python 的命令)。那时做。

rm /usr/bin/python3 
ln -s /usr/bin/python3.5 /usr/bin/python3 

~/.bash_aliases中创建别名

alias python3='/usr/bin/python3.6' 

脚本可以从以下内容开始:

#!/usr/bin/env python3 

【讨论】:

  • ln: failed to create symbolic link '/usr/bin/python3.6': File exists
  • 您需要交换ln 的参数才能工作:ln -s /usr/bin/python3.6 /usr/bin/python3
  • 对不起:/ ln -s /usr/bin/python3.6 /usr/bin/python3
  • 这个解决方案实际上破坏了我的 Ubuntu 终端。背景中的某些东西取决于python3 指向Python 3.5.3 而不是Python 3.6.1。不过不确定是什么。
  • 该死,在 Ubuntu 的大部分系统脚本和软件中都使用 Python,而软件依赖于在特定位置使用 Python(以及启动 Python 的命令)。然后再做。
    rm /usr/bin/python3 ln -s /usr/bin/python3.5 /usr/bin/python3 在 ~/.bash_aliases alias python3='/usr/bin/python3.6' 中创建别名然后脚本可以从以下内容开始:#!/usr/bin/env python3
【解决方案2】:

完美运行...

ln -sf /usr/bin/python3.5 /usr/bin/python3

【讨论】:

    【解决方案3】:

    您可以使用update-alternatives 命令在系统范围内更新默认的python 版本。

    $ sudo update-alternatives  --set python3 /usr/bin/python3.6
    

    或者您也可以运行以下命令在主机上安装的各种 python 版本中进行选择。

    $ sudo update-alternatives --config python
    

    【讨论】:

      【解决方案4】:

      如果您正在寻找的不是公认的答案。这是挽救我生命的解决方案。这是用新版本替换它。

      
      $ python3 --version
        Python 3.5.2
      
      $ ls -lh /usr/bin/python3
        lrwxrwxrwx 1 root root 9 Mar 23  2016 /usr/bin/python3 -> python3.5
      
      $ sudo mv /usr/bin/python3 /usr/bin/_python3
      $ sudo cp /usr/bin/python3.6 /usr/bin/python3
      
      $ python3 --version
        Python 3.6.11
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-30
        • 1970-01-01
        • 2014-05-27
        • 2011-12-18
        • 1970-01-01
        • 1970-01-01
        • 2012-11-11
        • 2021-11-21
        相关资源
        最近更新 更多