在ubuntu中切换默认python版本
有时候需要在默认python中使用不通版本的python,这里对于该操作做一下记录
当前版本(Ubuntu 18.04)
python3
结果是
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
可以看到,当前版本是3.6, 我们希望输入python3时使用的python版本为3.8
安装新版本python
sudo apt-get install python3.8
查看python3.8
python3.8
结果是
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
切换默认版本
查看系统下的python
whereis python
结果
python: /usr/bin/python3.6 /usr/bin/python2.7 /usr/bin/python3.6m /usr/bin/python3.8 /usr/lib/python3.6 /usr/lib/python2.7 /usr/lib/python3.8 /etc/python3.6 /etc/python2.7 /etc/python3.8 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/local/lib/python3.8
添加python3.8版本到python3
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
输出
update-alternatives: using /usr/bin/python3.8 to provide /usr/bin/python3 (python3) in auto mode
添加python3.6版本到python3
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6
2
输出
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in auto mode
查看python3中所有版本
update-alternatives --list python3
切换版本
update-alternatives --config python
按照提示切换版本
输入2之后,回车,测试版本切换是否成功
python3
输出
Python 3.8.0 (default, Dec 9 2021, 17:53:27)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
切换成功!!!