复制代码
1
2sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
切换
复制代码
1
2
3
4
5
6
7
8
9
10
11# 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)
复制代码
1
2
3
4
5$ 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. >>>
复制代码
1
2
3
4
5
6
7
8
9
10
11$ 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)
复制代码
1
2
3
4
5$ 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. >>>
移除
复制代码
1
2
3$ sudo update-alternatives --remove python /usr/bin/python2 update-alternatives: 正在移除手动选择的候选项 - 切换 python 到自动模式 update-alternatives: 使用 /usr/bin/python3 来在自动模式中提供 /usr/bin/python (python)
复制代码
1
2
3$ sudo update-alternatives --config python 链接组 python (提供 /usr/bin/python)中只有一个候选项:/usr/bin/python3 无需配置。
经测试,重启之后,依然生效。
转载于:https://www.cnblogs.com/jiqing9006/p/10661524.html
最后
以上就是花痴煎蛋最近收集整理的关于Ubuntu 下 Python自由切换的全部内容,更多相关Ubuntu内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复