Python介绍
Python 应用方向
- 后端 (web)
- 自动化 (Office Automation、Test)
- 数据()
Python 之禅
- 在确保安装好python的情况下:
- windows + R
- 输入python进入python交互环境
- import this
Beautiful is better than ugly. --> 优美胜于丑陋
Explicit is better than implicit. --> 明了胜于晦涩
Simple is better than complex --> 简洁胜于复杂
Flat is better than nested. --> 扁平胜于嵌套
Sparse is better than dense. --> 间隔胜于紧凑
Readability counts. --> 可读性很重要
编译器与解释器
- 区别
- 编译器:先整体编译再执行
- 解释器:边解释边执行
- Python接收器种类
- CPython
- Ipython
- PyPy
- Jython
Python环境搭建
- Python下载
- CLICK python 官网:http://www.python.org/
- CLICK Download
- CLICK Windows / Mac
- Ctrl + F Search Python 3.6.4
- Download Windows x86-64 executable installer
- Python 安装
- Open Install File
- CHOOSE Customize installation(CLICK Add Python 3.6 to PATH)
- ALL CHOOSE Optional Features
- MUST CHOOSE Add Python to environment variables
- CHOOSE LOCATION 除C盘外的其他地址 (记得安装地址)
- Install
- 添加环境变量
- Open My Desktop
- CLICK 鼠标右键 --> 属性
- CLICK 高级系统设置
- CLICK 环境变量
- CHOOSE 系统变量 --> Path --> 编辑
- CLICK 新建 --> COPY & PASTE “Python 存储路径”
- CLICK 新建 --> COPY & PASTE “Python Scripts 存储路径”
- 确定保存,以及重启 dos 命令行
pip的安装与使用
- pypi 仓库
- Python提供许多第三方库或模块,而PyPi就是一个统一的代码托管仓库。
- pip 介绍
- 在Python中,使用pip对pypi仓库中的第三方库进行安装、卸载、更新等操作命令。
-pip的基础使用 - 普通安装
- 进入DOS命令行
- 进入logic(系统环境) (python环境中不能install pip)
- 输入pip install pygame
- Successfully installed pygame
- 指定版本安装
- pip install pygame==2.2.0
- 卸载已安装
- pip uninstall pygame
- 列出已安装
- pip list
- pip freeze
- 导出所有pip文件
- pip freeze > D:\ requirement.txt 在D盘创建一个requirement的文本档案
- 安装导出的pip文件
- pip install -r D:\ requirement.txt
- 在Python中,使用pip对pypi仓库中的第三方库进行安装、卸载、更新等操作命令。
wheel 文件安装
-
- wheel 安装介绍与实现
- 介绍:在脱网前,将wheel格式文件下载到本地,然后使用pip进行安装
- 实现:
- pip install wheel 安装 wheel 这个库
- 打开网址 https://www.lfd.uci.edu/~gohlke/pythonlibs/
- Ctrl + F pygame
- CHOOSE pygame‑1.9.6‑cp36‑cp36m‑win_amd64.whl
- DOWNLOAD
- 将安装包迁移到python路径
- 在dos命令环境输入pip install + pygame wheel 文件路径 + 安装包名称
开启搬砖之旅 – 代码编辑器
- PyCharm编辑器介绍及下载
- PyCharm 安装地址https://www.jetbrains.com/pycharm/download/#section=windows
- CHOOSE Community
- DOWNLOAD
- 安装在C盘
- PyCharm的基础使用
- 配置Python解释器
- Open File --> Settings --> Project --> Project Interpreter
- 界面选择SETTING按钮 --> ADD
- 在Project Interpreter中添加至Python路径下的python.exe文件
- ALL OK
- 配置Python解释器
Python 作业
手动安装Python
手动配置python系统环境
pip whl 临时换源安装pygame
- pip 安装pygame
- pip卸载pygame
python idle、ipython、pycharm输出hello world
- python idle 输出 hello world
- ipython 输出 hello world
- PyCharm 输出 hello world
- 配置Python解释器