python 切换系统默认版本

目前系统默认python版本是2.7
在这里插入图片描述
需要切换成 python 3.8

  1. 确认 python 3.8 是否安装,使用命令:
python3.8

在这里插入图片描述
如未安装,使用命令,

sudo apt-get install python3.8
  1. 查看所有可用的python版本信息(注意:root身份 )
update-alternatives --list python 

报错:update-alternatives: error: no alternatives for python
在这里插入图片描述
错误原因:
Python 的替代版本尚未被 update-alternatives 命令识别

  1. 更新替代列表

update-alternatives: --install needs <link> <name> <path> <priority>

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2

可以根据自己的需要调整 priority

  1. 再次查看所有可用的python版本信息
update-alternatives --list python 

在这里插入图片描述

  1. 切换系统 python 版本

(因为在3中,设置的python 3.8的优先级高于python 2.7,所以此时系统中默认的python版本是python 3.8
在这里插入图片描述

当需要切换到python 2.7时,

update-alternatives --config python 

在这里插入图片描述
输入 python 验证,切换成功
在这里插入图片描述


版权声明:本文为weixin_43846270原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。