版权所有,未经许可,禁止转载
章节
Python 介绍
Python 开发环境搭建
Python 语法
Python 变量
Python 数值类型
Python 类型转换
Python 字符串(String)
Python 运算符
Python 列表(list)
Python 元组(Tuple)
Python 集合(Set)
Python 字典(Dictionary)
Python If … Else
Python While 循环
Python For 循环
Python 函数
Python Lambda
Python 类与对象
Python 继承
Python 迭代器(Iterator)
Python 模块
Python 日期(Datetime)
Python JSON
Python 正则表达式(RegEx)
Python PIP包管理器
Python 异常处理(Try…Except)
Python 打开文件(File Open)
Python 读文件
Python 写文件
Python 删除文件与文件夹
PIP是什么?
PIP是Python的包管理器,就像Java中的Maven。
注意: 如果是Python 3.4或更高版本,默认包含PIP。
什么是包?
一个包包含了一个模块的全部文件。
模块是Python代码库,可以在项目中导入、使用的。
检查是否安装了PIP
命令行中执行以下命令:
Kevin@KEVIN-PC C:\Users\Kevin
> pip --version
pip 19.0.3 from d:\program files\python\lib\site-packages\pip (python 3.7)
下载一个包
下载包非常简单。
打开命令行工具,执行pip install 包名
命令:
示例
下载一个名为“camelcase”的Python包:
Kevin@KEVIN-PC C:\Users\Kevin
> pip install camelcase
使用一个包
一旦安装了包,就可以使用它了。
将“camelcase”包导入到项目中。
示例
导入并使用“camelcase”:
import camelcase
c = camelcase.CamelCase()
txt = "long time no see"
print(c.hump(txt))
查找包
更多包请访问 https://pypi.org/。
删除包
可使用uninstall
命令删除一个包:
示例
卸载名为“camelcase”的包:
Kevin@KEVIN-PC C:\Users\Kevin
> pip uninstall camelcase
删除包过程中,将确认是否真要删除:
Uninstalling camelcase-0.2:
Would remove:
d:\program files\python\lib\site-packages\camelcase-0.2-py3.7.egg-info
d:\program files\python\lib\site-packages\camelcase\*
Proceed (y/n)? y
Successfully uninstalled camelcase-0.2
按下y
键,确认删除。
列出包
使用list
命令列出系统上安装的包:
示例
列出系统上安装的包:
Kevin@KEVIN-PC C:\Users\Kevin
> pip list
输出结果:
> pip list
Package Version
---------- -------
pip 19.0.3
setuptools 40.8.0
网友评论