美文网首页一起折腾Python
python2.7 和 python3.6切换

python2.7 和 python3.6切换

作者: He_Yu | 来源:发表于2018-11-23 21:42 被阅读14次

Operating System:Ubuntu 18.04

1. 设置优先级

这里我们默认让python3.6优先级150,高于python2.7优先级100

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

2.python2.7与python3.6的切换

sudo update-alternatives --config python

选中后输入0,选中python3(默认)
显示结果:

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,选中python2
显示结果:

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: 

相关文章

网友评论

    本文标题:python2.7 和 python3.6切换

    本文链接:https://www.haomeiwen.com/subject/jhmsqqtx.html