sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

切换

# sudo update-alternatives --config python
有 2 个候选项可用于替换 python (提供 /usr/bin/python)。 选择 路径 优先级 状态
------------------------------------------------------------
0 /usr/bin/python3 150 自动模式
* 1 /usr/bin/python2 100 手动模式
2 /usr/bin/python3 150 手动模式 要维持当前值[*]请按<回车键>,或者键入选择的编号:2
update-alternatives: 使用 /usr/bin/python3 来在手动模式中提供 /usr/bin/python (python)
$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ sudo update-alternatives --config python
有 2 个候选项可用于替换 python (提供 /usr/bin/python)。 选择 路径 优先级 状态
------------------------------------------------------------
0 /usr/bin/python3 150 自动模式
1 /usr/bin/python2 100 手动模式
* 2 /usr/bin/python3 150 手动模式 要维持当前值[*]请按<回车键>,或者键入选择的编号:1
update-alternatives: 使用 /usr/bin/python2 来在手动模式中提供 /usr/bin/python (python)
$ python
Python 2.7.15 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

移除

$ sudo update-alternatives --remove python /usr/bin/python2
update-alternatives: 正在移除手动选择的候选项 - 切换 python 到自动模式
update-alternatives: 使用 /usr/bin/python3 来在自动模式中提供 /usr/bin/python (python)
$ sudo update-alternatives --config python
链接组 python (提供 /usr/bin/python)中只有一个候选项:/usr/bin/python3
无需配置。

经测试,重启之后,依然生效。

Ubuntu 下 Python自由切换的更多相关文章

  1. ubuntu 下python版本切换

    1. 安装ubuuntu 14.04之后python的默认版本为2.7.6但是我想使用python的版本为3.4 可以打开终端:输入:alias python = python3

  2. ubuntu下python 2.7与python 3.X的转换

    ubuntu下python 2.7与python 3.X的转换 由于ubuntu本身自带python 2.7,而python 3.X与2.7有很多不同,所以在使用python 3.X时会带来诸多不便. ...

  3. ubuntu下python flask环境搭建

    ubuntu下python flask环境搭建 1. 安装pip sudo apt-get install python-dev pyhton-pip 2. 安装virtualenv sudo apt ...

  4. ubuntu 下python安装及hello world

    //@desn:ubuntu 下python安装及hello world //@desn:码字不宜,转载请注明出处 //@author:张慧源  <turing_zhy@163.com> ...

  5. ubuntu 下python环境的切换使用

    如何在Anaconda的python和系统自带的python之间切换 一般ubuntu下有三种python环境,1. 系统自带python2,3;在/usr/bin路径下:2. anaconda下安装 ...

  6. ubuntu下Python的安装和使用

    版权声明 更新:2017-04-13-上午博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Python的开发环境. ...

  7. Ubuntu 下Python 环境问题

    问题描述: 原先使用Anaconda环境,若卸载后仍不能恢复到系统默认的Python环境. 解决方案: shell 寻找缓存路径,python的扩展/home/tom/anaconda/bin/pyt ...

  8. Ubuntu下python两个版本的切换

    最近在Ubuntu16.04安装了python3.5还有系统自带的python2.7.13,总结一下不同版本的切换问题. alias:别名 bashrc:个人配置文件 一.修改Python版本(针对用 ...

  9. Ubuntu下python开发环境搭建

    配置语言 1) 依次点击设置--Region & Language--Manage Installed Languages --install/remove language--chinese ...

随机推荐

  1. STM32L476应用开发之六:电池SOC检测(转)

    源: STM32L476应用开发之六:电池SOC检测

  2. MyBatis中#{ }和${ }的区别,数据库优化遵循层次和查询方法

    MyBatis中#{ }和${ }的区别详解 1.#将传入的数据当成一个字符串,会对自动传入的数据加一个 双引号. 例如order by #id#,如果传入的值是111,那么解析成sql时变为orde ...

  3. select2 AJAX获取数据

    页面效果: index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"& ...

  4. Deep Learning for NLP

    Deep Learning for NLP The First Paper Proposed Bi-LSTM+CRF 我认为,第一篇提出 Bi-LSTM+CRF 架构的文章是: Huang Z, Xu ...

  5. 12: xlrd 处理Excel文件

    1.1 xlrd处理.xlsx 文件 1.xlrd常用方法 #!/usr/bin/python # coding:utf-8 # 用xlrd读取Excel文件基本用法 import sys impor ...

  6. 牛客练习赛24题解(搜索,DP)

    A题,C题不讲,基础题(但是我要抨击一下这次比赛,卡cin,cout,卡的太狠了,根本就不让过的那种,QAQ) 链接:https://www.nowcoder.com/acm/contest/157/ ...

  7. Python函数的作用域规则和闭包

    作用域规则 命名空间是从名称到对象的映射,Python中主要是通过字典实现的,主要有以下几个命名空间: 内置命名空间,包含一些内置函数和内置异常的名称,在Python解释器启动时创建,一直保存到解释器 ...

  8. 位运算之a^b

    题目链接:https://www.acwing.com/problem/content/91/ 参考链接:https://blog.csdn.net/chaiwenjun000/article/det ...

  9. GDPR

    http://column.caijing.com.cn/20180523/4457753.shtml

  10. linux --- 3 vim 网络 用户 权限 软连接 压缩 定时任务 yum源

    一.vi 和vim vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方. vim 则可以说是程序开发者的一项很好用的工具 ①命令模式 移动光标 w(e) 移动光标到下一个单词 b ...