Python 的安装与配置(图文教程)
安装 Python
想要进行 Python 开发,首先需要下载和配置 Python 解释器。
下载 Python
访问 Python 官网: https://www.python.org/
点击 downloads 按钮,在下拉框中选择系统类型 (windows/Mac OS/Linux 等)
选择下载最新版本的 Python

安装 Python
双击下载好的 Python 安装包
勾选左下角 Add Python 3.7 to PATH 选项,然后选择 Install now 立刻安装 Python.

安装完成
测试是否安装成功
点击电脑左下角开始按钮,输入 cmd 进入到 windows 的命令行模式。
在命令行中输入 Python, 正确显示 Python 版本,即表示 Python 安装成功

如果在命令行中输入 python 出现如下错误

可能是因为在安装 Python 的过程中没有勾选 Add Python 3.7 to PATH 选项,此时需要手动对 Python 进行配置。
手动配置 Python
注意:如果在安装过程中,已经勾选了 Add Python 3.7 to PATH 选项,并且在 cmd 命令模式下输入 python 指令不报错,就不需要再手动的配置 Python.
右键此电脑 --> 选择 属性

选择高级系统设置 --> 环境变量 --> 找到并且双击 Path

双击 Path, 在弹框里点击新建,找到 Python 的安装目录,把路径添加进去

这里新添加的路径 C:\Users\chris\AppData\Local\Programs\Python\Python37 是 Python 安装好以后,Python.exe 这个可执行文件所在的目录。、

pip 的使用
pip 是一个现代的,通用的 Python 包管理工具。提供了对 Python 包的查找、下载、安装、卸载的功能,便于我们对 Python 的资源包进行管理。
安装
在安装 Python 时,会自动下载并且安装 pip.
配置
在 windows 命令行里,输入 pip -V 可以查看 pip 的版本。

如果在命令行里,运行 pip -V, 出现如下提示:

可能是因为在安装 python 的过程中未勾选 Add Python 3.7 to PATH 选项,需要手动的配置 pip 的环境变量。
右键此电脑 --> 环境变量 --> 找到并且双击 Path--> 在弹窗里点击新建 --> 找到 pip 的安装目录,把路径添加进去。

这里新添加的路径 C:\Users\chris\AppData\Local\Programs\Python\Python37\Scripts 是 Python 安装好以后,pip.exe 这个可执行文件所在的目录。

使用 pip 管理 Python 包
pip install <包名> 安装指定的包
pip uninstall <包名> 删除指定的包
pip list 显示已经安装的包
pip freeze 显示已经安装的包,并且以指定的格式显示
pip install -r required.txt 安装 required.txt 文件里列出的安装包
修改 pip 下载源
运行 pip install 命令会从网站上下载指定的 python 包,默认是从https://files.pythonhosted.org/ 网站上下载。这是个国外的网站,遇到网络情况不好的时候,可能会下载失败,我们可以通过命令,修改 pip 现在软件时的源。 格式:
pip install 包名 -i 国内源地址
示例: pip install flask -ihttps://pypi.mirrors.ustc.edu.cn/simple/ 就是从中国科技大学 (ustc) 的服务器上下载 flask (基于 python 的第三方 web 框架)
评论