ubuntu20安装python2, python3及版本配置

默认安装了python3

一. 安装Python2.7

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

上述两条命令将/usr/bin/python2.7优先级设置为1,将/usr/bin/python3.8的优先级设置为2,所以执行update-alternatives命令后,python3.8被设置为系统默认版本。

2.验证
python --version    查看当前默认版本
update-alternatives --list python  显示python代替版本信息
update-alternatives --config python  手动切换python默认版本

二. 安装pip

#安装python3-pip
apt install python3-pip

#安装python-pip, 切换到python2.7时执行
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python get-pip.py

经过以上配置,python2.7和python3.8及对应版本pip已全部安装好,当手动切换python版本后,对应的pip默认版本也会改变

参考:
https://www.ngui.cc/el/1276661.html?action=onClick
https://www.niuqi360.com/linux/install-python-3-9-on-ubuntu-20-04/

posted @ 2022-12-27 18:18  坚强的小蚂蚁  阅读(1476)  评论(0编辑  收藏  举报