zoukankan      html  css  js  c++  java
  • 更改Ubuntu默认python版本的方法

    Ubuntu系统中会存在多个 Python 的可执行二进制文件。一般Ubuntu默认的Python版本都为2.x, 如何改变Python的默认版本呢?下面来一起看看吧。

    你可以按照以下方法使用 ls 命令来查看你的系统中都有那些 Python 的二进制文件可供使用。

    $ ls /usr/bin/python*

    像我的有2.7、3、3.5版本

    我们可以使用 update-alternatives 来为整个系统更改 Python 版本。以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:

    # update-alternatives --list python
    update-alternatives: error: no alternatives for python

    如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。想解决这个问题,我们需要更新一下替代列表,将 python2.7 和 python3.5 放入其中。

    # 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
    # update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
    update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode

    --install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 /usr/bin/python3.5 设置的优先级为2,所以update-alternatives 命令会自动将它设置为默认 Python 版本。

    接下来,我们再次列出可用的 Python 替代版本。

    # update-alternatives --list python
    /usr/bin/python2.7
    /usr/bin/python3.5

    现在开始,我们就可以使用下方的命令随时在列出的 Python 替代版本中任意切换了。

    # update-alternatives --config python
  • 相关阅读:
    Moodle 3.8 安装过程
    Discourse 数据分发
    Moodle 安装的时候提示 original IP
    Apache 安装运行测时候提示错误 (13)Permission denied: AH00091: httpd: could not open error log file
    Apache 配置 SELinux 命令的时候的命令 semanage
    Apache Httpd 安装 AH00558错误
    Discourse 如何修改用户自己的密码
    Discourse 如何限制注册用户的密码长度
    Discourse 的快捷键列表
    S3 存储附件和图片无法上传
  • 原文地址:https://www.cnblogs.com/python-learning-blog/p/11338794.html
Copyright © 2011-2022 走看看