背景介绍
pip是python的一个包管理工具,如果我们想为我们的python项目导入一些三方的库,其实是很方便的
安装
pip install SomePackage
// 例如 for example
pip install SomePackage-1.0-py2.py3-none-any.whl
没错就是这么的方便,只需要pip install即可,
python pypi管理
https://pypi.org/search/?q=docker,在之前我们如果想要查找其他的项目或者依赖是比较麻烦,因为这个是官方最近才退出来的项目,项目搜索姿势,搜索表单提交你要搜索的关键词即可,
项目详情页列出了安装方式,简介,如何使用,文档,以及作者,开源项目地址,还有关注热度。所以开发python的项目变得越来越方便,可以搜索到更多的项目,
以及学习到更多的优秀项目。
安装pip
获取源码
wget https://bootstrap.pypa.io/get-pip.py
#or
curl https://bootstrap.pypa.io/get-pip.py -o setup-pip.py
# install
python setup-pip.py
# check install and version
root@ubuntu:/# pip -V
pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
没错安装就是这么的方便
pip常用命令介绍
root@ubuntu:/# pip -v
Usage:
pip [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
pip install 安装包
pip download 下载包
pip uninstall 卸载包
pip list 查看已经下载安装的包
pip config 查看配置
pip search 搜索资源包
pip help 查看命令
pip国内镜像资源,提升你的下载和安装速度
pip安装资源是一件比较频繁的操作,但是这些资源如果需要从国外下载下来的话十分的缓慢,而且极容易出错,所以我们需要配置为国内的镜像地址
国内资源
新版ubuntu要求使用https源,要注意。
临时安装
pip install -i http://pypi.douban.com/simple scrapy
修改配置,永久安装
vim ~/.pip/pip.conf
[global]
timeout = 60
index-url = https://pypi.douban.com/simple
修改index-url即可
requirement.txt的使用
requirement.txt里面是放置了这个项目所以依赖的所有的依赖,一个列表,一个依赖一行。
如:
scrapy
pymysql
...
pip如何执行批量安装,如何批量安装requirement.txt
pip install -r requirement.txt
# usage
pip install -h
# -r, --requirement Install from the given requirements file. This option can be used multiple times.
#
总结
随着项目越来越大,我们就需要一个统一的工具来管理我们的项目模块和三方库,pip是不二之选
善用工具,善于查找,google, linux 命令加-h or help,或者man命令,都可以帮我们很快找到我们想要的说明
当然前提是我们的英语至少可以阅读理解
参考网址