在Linux上升级Python版本

  1. 首先可以使用以下命令查看当前的python版本:
python3 -V
  1. 安装最新版python, 以python 3.8为例:
apt update
apt install python3.8
  1. 将原版本的python和python3.8添加到update-alternatives中:
 update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6  1
 update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8  2
#可以使用 whereis python3 命令在linux中确定python的目录
#上述命令结尾的数字代表优先级, 系统跟据优先级选择默认的python版本
  1. 可以跟据需要自由切的python3命令的指向:
 update-alternatives --config python3

auto mode是跟据优先级自动选择.

root@markict:~# update-alternatives --config python3 
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.8   2         auto mode
  1            /usr/bin/python3.6   1         manual mode
  2            /usr/bin/python3.8   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 0
  1. 版本升级成功:
python3 -V
root@markict:~# python3 -V
Python 3.8.0
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容