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版本,他们需要重复上述步骤。

相关推荐
用户83562907805111 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng813 小时前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi14 小时前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee14 小时前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay14 小时前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤14 小时前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean15 小时前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
曲幽16 小时前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户606487671889617 小时前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api
只与明月听18 小时前
RAG深入学习之Chunk
前端·人工智能·python