
第1章 Python语言基础
1.1 安装Python环境
1.1.1 Python 3.6.2安装与配置
根据Windows版本(64位/32位)从Python官网上下载对应的版本,如图1-1所示。

图1-1
下载完成后,双击文件以运行安装程序安装Python,如图1-2所示。

图1-2
STEP 1:勾选“Add Python 3.6 to PATH”选项后单击“Customize installation”选项。
“Add Python 3.6 to PATH”选项用于将Python 3.6加入系统路径,勾选该选项会使日后的操作非常方便;如果没有勾选这个选项,就需要手动为系统的环境变量添加路径。
STEP 2:在弹出的界面中勾选所有的选项,并单击“Next”按钮,如图1-3所示。
选项“Documentation”表示安装Python的帮助文档;选项“pip”表示安装Python的第三方包管理工具;选项“tcl/tk and IDLE”表示安装Python的集成开发环境;选项“Python test suite”表示安装Python的标准测试套件;最后两个选项则表示允许版本更新。

图1-3
STEP 3:保持默认勾选状态,单击“Browse”按钮,选择安装路径,如图1-4所示。

图1-4
STEP 4:单击“Install”按钮,直至完成安装。
完成安装后,调出命令提示符,输入“python”,检查是否安装成功。如果Python安装成功,则将出现如图1-5所示的界面,即输入“python”后会看到“>>>”符号。

图1-5
1.1.2 使用IDE工具——PyCharm
安装好环境后,还需要配置一个程序员专属工具,即PyCharm,它是一个适合用于开发的多功能IDE(集成开发环境),下载社区版(免费版)。
笔者使用的版本是2017.2.2,发行日期是2017年8月24日,可以从PyCharm官网上下载,如图1-6所示。

图1-6
PyCharm非常好用,通过PyCharm可以下载、安装和管理库。
1.1.3 使用IDE工具——Anaconda
Anaconda是一个专门用于统计和机器学习的IDE,它集成了Python和许多基础的库,如果业务场景是统计和机器学习,那么只要安装一个Anaconda就可以了,从而省去许多复杂的配置过程。
Anaconda可以通过官网下载,如图1-7所示。
这里默认下载的是64位的版本,如果需要下载32位的版本,则可以单击“Download”按钮下的文字链接。
使用Anaconda不需要提前安装Python,安装后即可运行:使用快捷键【Windows+R】打开“运行”对话框,在“打开”文本框中输入“ipython jupyter”,然后单击“确定”按钮,如图1-8所示。

图1-7

图1-8