Ubuntu中切换默认python版本

在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

按照提示切换版本

image-20220922154629165

输入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.
>>>

切换成功!!!

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值