本文将分别介绍 Python、Anaconda/Miniconda、PyCharm 的安装、配置与使用,详细介绍 Python 环境搭建的全过程,涵盖 Python、Pip、Python Launcher、Anaconda、Miniconda、Pycharm等内容,以官方文档为参照,使用经验为补充,内容全面而详实,后附本教程文档,共20多页5000余字。
Python 的安装与配置
下载
访问 Python官网,进入下载页面,选择合适的版本。
如图 1.1 所示,在 Python 官网的下载页面,可以选择操作系统和版本。
以 Windows 为例,下载页面提供了直接下载最新版本的入口,点击 Download 即可下载 exe 安装程序。
如果需要下载 Python 的其他版本,则下滑动下载页面,如图 1.2 所示,可以看到 Python 的各个发行版本,选择所需版本,点击右侧 Download,进入相应版本详情页面,下滑详情页面,找到 Files 栏,如图 1.3 所示。
版本详情页面的 Files 栏如图 1.3 所示,可以看到有多个下载链接,该如何选择呢?
版本 | 操作系统 | 说明 |
---|---|---|
Gzipped source tarball | Linux | .tgz 格式压缩包 |
XZ compressed source tarball | Linux | .tar.xz 格式压缩包 |
macOS 64-bit universal2 installer | 64位 macOS | .pkg 格式安装程序 |
Windows installer (64-bit) | 64位 Windows,x86 架构 | .exe 格式安装程序 |
Windows installer (32-bit) | 32位 Windows,x86 架构 | .exe 格式安装程序 |
Windows installer (ARM64) | 64位 Windows,arm架构 | .exe 格式安装程序 |
Windows embeddable package (64-bit) | 64位 Windows,x86 架构 | .zip 格式压缩包 |
Windows embeddable package (32-bit) | 32位 Windows,x86 架构 | .zip 格式压缩包 |
Windows embeddable package (ARM64) | 64位 Windows,arm架构 | .zip 格式压缩包 |
目前仅介绍 Windows 下的安装,后续有需要再更新 Linux 下的安装,以下均以 Windows 为例。
安装程序和压缩包的区别可参考 在 Windows 上使用 Python,主要区别在于,相对于安装包,压缩包不包含 Tcl/tk、pip、Python 文档。还有就是,使用安装包安装,用户可以通过图形化界面完成某些配置,使用压缩包安装,用户需要手动显式完成这些配置。
The standard library is included as pre-compiled and optimized
.pyc
files in a ZIP, andpython3.dll
,python37.dll
,python.exe
andpythonw.exe
are all provided. Tcl/tk (including all dependents, such as Idle), pip and the Python documentation are not included.
以下分别介绍安装包安装(新手)和压缩包安装。
安装程序安装
双击 exe
安装程序,进入图 1.4 所示界面。

Install Now:立即安装,使用默认安装配置,包括安装路径、安装选项。
- IDLE:Integrated Development and Learning Environment,集成开发与学习环境,在其中可以完成编写、运行、调试代码,详情参照 IDLE - Python文档。
- pip:pip 是一个现代的,通用的 Python 包管理工具,详情参照 pip · PyPI,pip 的配置与使用见后文。
Customize installation:自定义安装,指定安装位置和安装选项。
Use admin privileges when installing py.exe:以管理员权限安装 Python,若勾选,则安装后当前电脑的其他用户可直接使用 Python,若不勾选,则此次安装的 python 仅当前用户可以使用。虽然 Windows 支持多用户,但个人电脑一般就只会创建一个用户,所以这里我选择不勾选。
Add python.exe to PATH:将 python.exe 添加到系统环境变量,添加之后,在系统的任何路径下均可直接使用 python
命令。为避免后续手动设置环境变量,此项可勾选,但为了演示设置环境变量,这里我选择不勾选。
点击 Customize installation,进入图 1.5 所示界面。

Documentation:Python 文档。文档可在线查阅和下载,可选可不选。
pip:Python包管理工具,勾选。
tcl/tk and IDLE:tcl/tk 与构建图形界面相关,tkinter 是标准 GUI 库,是 tcl/tk 工具包的 Python 接口。IDLE 是 Python 的集成开发与学习环境。若需要 tkinter,可手动下载,集成开发环境一般使用 PyCharm,故此项不勾选。
Python test suite:Python 测试套件。测试套件标准库可在有需要的时候手动安装,故此项不勾选。
py launcher:Python 启动器,当安装有多个版本的 Python 时,可通过 py
命令指定执行脚本的 Python 解释器,详细介绍见后文。由于未找到单独下载 py launcher 的入口,此项先勾选。
for all users (requires admin privileges):若勾选,则系统中的所有用户均可直接使用该 py launcher,该项与图 4 中的 Use admin privileges when installing py.exe 勾选状态是同步的,故此项不勾选。
点击 Next,进入图 1.6 所示界面。

Install Python 3.12 for all users:为所有用户安装。不勾选。
Associate files with Python (requires the ‘py’ launcher):关联 .py
等文件,需要安装 py launcher,关联后,双击 .py
等文件,可直接调用 py launcher 执行。
Create shortcuts for installed applications:创建快捷方