跳转至

🐍 Python / FastAPI


python vs python3 的区别

历史原因

  • Python 2(python)已于 2020 年废弃
  • Python 3(python3)是当前主流

为什么有两个命令

  • python → 系统默认,可能是 Python 2 或 3,取决于系统配置
  • python3 → 明确指定 Python 3,不会搞混

不同系统表现

  • macOS 老版本:python → Python 2.7,python3 → Python 3.x
  • macOS 新版本:python 可能不存在,python3 → Python 3.x
  • Ubuntu 20.04+:python 可能不存在,python3 → Python 3.x
  • CentOS 7:python → Python 2.7

最佳实践

  • 永远用 python3,明确指定版本
  • python3 script.py > python script.py
  • Python 2 已废弃,很多库不支持

验证命令

python --version
python3 --version
which python
which python3