前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubuntu16.04切换python版

Ubuntu16.04切换python版

作者头像
py3study
发布2020-01-13 16:36:10
7870
发布2020-01-13 16:36:10
举报
文章被收录于专栏:python3python3

ubuntu16.04中默认已经安装了python2.7和python3.5

代码语言:text
复制
hanli@ubuntu:/usr/bin$ ls |grep python
dh_python2
dh_python3
python
python2
python2.7
python2.7-config
python2-config
python3
python3.5
python3.5m
python3m
python-config
x86_64-linux-gnu-python2.7-config
x86_64-linux-gnu-python-config
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

怎么切换?

1.现在是2.7

代码语言:ruby
复制
hanli@ubuntu:/usr/bin$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
  • 1
  • 2

2.执行两条命令

代码语言:ruby
复制
hanli@ubuntu:/usr/bin$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in auto mode
hanli@ubuntu:/usr/bin$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode
  • 1
  • 2
  • 3
  • 4

3.再次查看已经变成3.5了

代码语言:ruby
复制
hanli@ubuntu:/usr/bin$ python
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
  • 1
  • 2

4.怎么随意切换

代码语言:text
复制
hanli@ubuntu:/usr/bin$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3   150       auto mode
  1            /usr/bin/python2   100       manual mode
  2            /usr/bin/python3   150       manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in manual mode

#数字前面有*号表示是当前使用版本,输入1切换到2.7,再次查看如下

hanli@ubuntu:/usr/bin$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3   150       auto mode
* 1            /usr/bin/python2   100       manual mode
  2            /usr/bin/python3   150       manual mode

Press <enter> to keep the current choice[*], or type selection number:
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档