- 从零开始学Python
- 高博等
- 782字
- 2025-02-20 14:05:04
2.1 在Windows上安装Python开发环境
Python的主要发行版本有2.X和3.X两大分支,许多使用早期Python 2.X版本编写的程序都无法在Python 3.X上正常执行。为了兼容这些程序,Python 2.6作为一个过渡版本,基本使用了Python 2.X的语法和库,同时考虑了Python 2.X向Python 3.X的迁移,允许使用部分Python 3的语法与函数。Python官方建议新的程序使用Python 3.X的语法,除非运行环境无法安装Python 3或程序本身使用了不支持Python 3的第三方库。而即使无法立即使用Python 3,也建议编写兼容Python 3版本的程序,然后使用Python 2.6或Python 2.7来执行。下面介绍Python 3.7.2运行环境在Windows 7旗舰版SP1操作系统上的安装过程。
Step 01 打开浏览器,在地址栏输入“https://www.python.org/”,进入Python官网,单击“Downloads”导航栏,如图2-1所示。

图2-1 进入Python官网
Step 02 进入下载页面,单击“Windows”链接,如图2-2所示。

图2-2 进入Windows版本下载页面
Step 03 单击“Latest Python 3 Release-Python 3.7.2”(这是截至本书写作时最新的发布版本)链接,如图2-3所示。

图2-3 进入最新发布版本下载页面
Step 04 将浏览器页面向下滚动到如图2-4所示的位置,根据当前操作系统的类型单击相应的链接下载Python安装程序,如操作系统是64位则单击图中链接1,操作系统是32位则单击图中链接2。

图2-4 根据操作系统的类型下载Python安装程序
Step 05 运行下载的Python安装程序,系统显示如图2-5所示的安装界面(图中运行的是64位安装程序),勾选“Add Python 3.7 to PATH”单选项,然后单击“Customize installation”按钮。

图2-5 运行Python安装程序
Step 06 进入下一步,此处复选框默认全部勾选,不做任何改动,单击“Next”按钮即可,如图2-6所示。

图2-6 确认需要安装的功能
Step 07 进入安装配置界面,可根据需要勾选相应的选项。笔者除了默认的选项外,还勾选了“Install for all users”和“Precompile standard library”两项,此时下方的“Customize install location”从默认的“C:\Users\Administrator\AppData\Local\Programs\Python\Python37”变成了“C:\Program Files\Python37”,单击“Install”按钮开始安装,如图2-7所示。

图2-7 选择安装配置选项
Step 08 等待安装程序自动执行安装过程,如图2-8所示。

图2-8 等待安装过程
Step 09 当显示如图2-9所示的界面时即表示Python环境已经成功安装,单击“Close”按钮关闭安装程序。

图2-9 安装成功