Ubuntu 安装python3及多版本切换
Ubuntu上python版本查看
$ python -V Python 2.7.12
1.安装3.7
添加源
sudo add-apt-repository ppa:deadsnakes/ppa
检查更新
sudo apt-get update
安装python3.7
sudo apt-get install python3.7
安装pip3
sudo apt install python3-pip
2.使用 update-alternatives 来为整个系统更改Python 版本
查看python替代版本信息
~$ update-alternatives --display python
但是结果为
update-alternatives: error: no alternatives for python
python的替代版本尚未被update-alternatives
查看python的位置
$ whereis python python: /usr/bin/python2.7 /usr/bin/python3.7 /usr/bin/python3.5m /usr/bin/python3.7m /usr/bin/python3.5 /usr/bin/python /usr/lib/python2.7 /usr/lib/python3.7 /usr/lib/python3.5 /etc/python2.7 /etc/python3.7 /etc/python3.5 /etc/python /usr/local/lib/python2.7 /usr/local/lib/python3.7 /usr/local/lib/python3.5 /usr/share/python /usr/share/man/man1/python.1.gz
更新一下替代列表
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode baby@ubuntu:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2 update-alternatives: using /usr/bin/python3.7 to provide /usr/bin/python (python) in auto mode
查看python替代版本信息
$ update-alternatives --display python python - auto mode link best version is /usr/bin/python3.7 link currently points to /usr/bin/python3.7 link python is /usr/bin/python /usr/bin/python2.7 - priority 1 /usr/bin/python3.7 - priority 2
查看python版本
$ python -V Python 3.7.9
3.切换版本
切换到2.7
$ sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/python3.7 2 auto mode 1 /usr/bin/python2.7 1 manual mode 2 /usr/bin/python3.7 2 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode baby@ubuntu:~$ python -V Python 2.7.12
pip版本
$ pip -V pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
切换到3.7
sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/python3.7 2 auto mode * 1 /usr/bin/python2.7 1 manual mode 2 /usr/bin/python3.7 2 manual mode Press <enter> to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/bin/python3.7 to provide /usr/bin/python (python) in manual mode baby@ubuntu:~$ python -V Python 3.7.9
安装pip
sudo apt install python3-pip
pip版本
pip -V pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.7)
pip的版本随着python版本切换
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2017-01-05 使用Amoeba for mysql实现mysql读写分离
2017-01-05 Mysql主从架构的复制
2017-01-05 Redis-Sentinel(Redis集群监控管理)
2016-01-05 GridView多表关联