Ubuntu1804下如何切换python版本

Ubuntu1804下如何切换python版本


目录

[1 如何查看当前python版本](#1 如何查看当前python版本)
[2 如何配置默认python版本](#2 如何配置默认python版本)

[2.1 配置python2为默认版本](#2.1 配置python2为默认版本)

[2.2 配置python3为默认版本](#2.2 配置python3为默认版本)
[3 小结](#3 小结)


1 如何查看当前python版本

可以用过以下命令,查看当前python默认版本:

复制代码
python --version

2 如何配置默认python版本

2.1 配置python2为默认版本

可以用过以下命令进行设置:

复制代码
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1

也可以用过以下命令在弹出的命令行选择界面进行设置:

复制代码
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   1         auto mode
  1            /usr/bin/python2   1         manual mode
* 2            /usr/bin/python3   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 

2.2 配置python3为默认版本

操作方式同上。


3 小结

这种设置方式只适用于当前用户,如果其他用户也想设置默认Python版本,他们需要重复上述步骤。

相关推荐
databook9 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室9 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三11 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271114 小时前
Python之语言特点
python
刘立军15 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机18 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机19 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i21 小时前
django中的FBV 和 CBV
python·django
c8i21 小时前
python中的闭包和装饰器
python
这里有鱼汤1 天前
小白必看:QMT里的miniQMT入门教程
后端·python