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. Action的编写方式

    四.Action 的编写方式 : 三种 第一种 创建普通类 不继承任何类,不实现任何接口 Public class HelloAction{  } 第二种 创建类,实现接口action Public ...

  2. Kattis之旅——Eight Queens

    In the game of chess, the queen is a powerful piece. It can attack by moving any number of spaces in ...

  3. Inception 模型

    https://blog.csdn.net/xxiaozr/article/details/71481356 inception v1: 去除了最后的全连接层,使用全局平均池化层来代替,因为全连接层的 ...

  4. no matching editors or conversion strategy found

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionM ...

  5. Golang命令行拷贝文件

    package main import ( "fmt" "io" "os" ) func main() { list := os.Args ...

  6. python2.7安装mysql-python

    环境:python2.7.14+mysql-python-1.2.3.win-amd64-py2.7.exe 安装版本许参照解释器版本,有64和32位之分,如果安装错误版本,则运行时会报错:Impor ...

  7. UI简述

    UI的全称是user interface,即是用户界面.UI设计是指对软件的人机交互,操作编辑,界面美观的整体设计,从简单的角度来说就是,UI是视觉上的东西,包括logo.软件.网页的按钮.网页导航, ...

  8. kali linux 64bit 2019.1a下启动bbqsql:No module named coros

    kali linux 64bit 2019.1a下bbqsql启动失败,错误: File "/usr/local/lib/python2.7/dist-packages/bbqsql/lib ...

  9. jQuery 表单内容的获取

    var formData = $('#myform').serialize()

  10. c++ vector常见用法

    //输出尾巴的元素 cout<<vec.back(); //定义vector迭代器 vector<int>::iterator ite=vec.begin(); for(ite ...