1. Windows
下载和安装
-
下载 Python 安装包:
- 访问 Python 官方网站。
- 在下载页面选择适合你操作系统的 Python 版本(建议下载最新的稳定版本)。
- 点击下载 Windows 版本的安装程序(通常是
.exe文件)。
-
运行安装程序:
- 双击下载的
.exe文件启动安装程序。 - 在安装向导中,勾选 “Add Python to PATH” 选项。这将把 Python 添加到系统环境变量中,便于从命令行调用。
- 选择 “Customize installation” (可选)以自定义安装选项,如添加 pip、安装文档等。
- 点击 “Install Now” 按钮开始安装。
- 双击下载的
-
验证安装:
-
打开命令提示符(CMD)或 PowerShell。
-
输入以下命令检查 Python 版本:
bash 复制代码 python --version -
或者使用:
bash 复制代码 py --version -
如果 Python 安装正确,你会看到 Python 版本号的输出。
-
2. macOS
下载和安装
-
下载 Python 安装包:
- 访问 Python 官方网站。
- 下载适用于 macOS 的最新 Python 安装包(
.pkg文件)。
-
运行安装包:
- 双击下载的
.pkg文件启动安装程序。 - 按照安装向导的指示完成安装。
- 双击下载的
-
验证安装:
-
打开终端(Terminal)。
-
输入以下命令检查 Python 版本:
bash 复制代码 python3 --version -
在 macOS 上,Python 3 通常用
python3命令来调用,而 Python 2.x 用python命令(如果存在)。
-
3. Linux
通过包管理器安装
-
Ubuntu/Debian 系列:
-
打开终端。
-
更新包列表并安装 Python :
bash 复制代码 sudo apt update sudo apt install python3 -
安装 pip(Python 包管理器):
bash 复制代码 sudo apt install python3-pip
-
-
Fedora/RHEL/CentOS 系列:
-
打开终端。
-
安装 Python 和 pip:
bash 复制代码 sudo dnf install python3 sudo dnf install python3-pip -
在较旧的 CentOS/RHEL 系统上,可能需要使用
yum代替dnf。
-
-
验证安装:
-
输入以下命令检查 Python 版本:
bash 复制代码 python3 --version
-