Why learn Python?
-
Web and Internet Development
-
Scientific and Numeric
Python is widely used in scientific and numeric computing:- SciPy is a collection of packages for mathematics, science, and engineering.
- Pandas is a data analysis and modeling library.
- IPython is a powerful interactive shell that features easy editing and recording of a work session, and supports visualizations and parallel computing.
- The Software Carpentry Course teaches basic skills for scientific computing, running bootcamps and providing open-access teaching materials.
-
Education
Python is a superb language for teaching programming, both at the introductory level and in more advanced courses. -
Desktop GUIs
-
Software Development
Python is often used as a support language for software developers, for build control and management, testing, and in many other ways. -
Business Applications
Python is also used to build ERP and e-commerce systems.
For more detail:https://www.python.org/about/apps/
安装环境
- 系统:Windows10 64-bit
- 用于演示安装的Python版本号
- Release version:Python 3.8.7
- Release date:Dec.21.2020
- 官网:https://www.python.org/downloads/
安装步骤
-
在官网中选择Python 3.8.7版本,下拉找到标题为Files的一栏,即对应不同类型的安装包。
-
推荐选择Windows installer(64-bit)进行下载,或根据实际需求选择不同操作系统/不同平台的安装包。
-
下载完成后,打开安装Python安装程序
- Python 支持两种安装方式,默认安装和自定义安装。默认安装会勾选所有组件,并安装在 C 盘;自定义安装可以手动选择要安装的组件,并安装到其它盘符。
- 这里我们选择自定义安装,即点击“Customize installation”,后续步骤可将 Python 安装到常用的目录,避免C盘文件过多。
- 对于编程小白或者对环境管理不熟悉的朋友,请尽量勾选Add Python 3.8 to PATH,这样可以将 Python 命令工具所在目录添加到系统 Path 环境变量中,以后开发程序或者运行 Python 命令会非常方便。
-
选择需要安装的Python组件,默认全部安装即可,这里包含我们开发需要的文档Documentation, pip管理包和集成开发环境IDLE。
-
确定安装路径。
-
点击“Install”,等待几分钟就可以完成安装。安装完成后点击Close关闭即可。
单元测试
-
由于在上述安装过程中选择了"Add Python 3.8 to Path",即配置了环境变量,因此在命令行状态下输入python就可以调用。如果出现 Python 的版本信息,并看到命令提示符>>>,就说明安装成功了,如下图所示。
-
在win10开始菜单栏中找到IDLE,或者在 Python 安装路径的
Lib\idlelib
目录下找到"idle.bat"打开。IDLE即Integrated Development and Learning Environment,是Python官方提供的集成开发和学习环境,它完全用 Python 和 Tkinter GUI 工具包编写,该环境虽然简单,但满足了新手学习的大部分功能。
与普通的命令行相比,IDLE的交互式环境具有语法高亮的功能,并且按下Tab键会出现代码提示,如下图所示。
点击 File - New File ,可新建并编辑.py文件,点击 Run - Run Module 后可运行,一个简单的演示如下图所示。
使用pip工具管理包、第三方库等
-
查看已安装包,命令为pip list。
-
提示可更新pip,若已配置python环境变量,可使用命令python -m pip install --upgrade pip。
-
使用pip安装科学计算包numpy,命令为pip install numpy。python会从https://pypi.org/上下载对应的Package。【The Python Package Index (PyPI) is a repository of software for the Python programming language】。但国内对此网站的访问下载速度太慢,可能导致报错,为了避免 Error 并加快下载速度,可使用国内的镜像源下载,如使用命令pip install numpy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
-
再次使用命令pip list查看已安装包,可以看见出现numpy及其版本信息。
-
在命令行中打开 Python ,输入 import numpy ,若无报错,则说明库安装成功。其它第三方库的pip安装方法同理。