pip
pip是一个Python包管理工具,主要是用于安装PyPI上的软件包,可以替代easy_install工具
安装
在线安装
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
离线安装
python pip-9.0.1-py2.py3-none-any.whl/pip install pip-9.0.1-py2.py3-none-any.whl
pip-9.0.1-py2.py3-none-any.whl需要更换为实际的wheel安装包
使用
➜ Downloads pip -h
Usage:
pip <command> [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.
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.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user
configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding
to WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup,
(a)bort.
--trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the
certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is
available for download. Implied with --no-index.
| 命令 | 说明 |
|---|---|
| search | 查找安装包 |
| install | 安装安装包 |
| uninstall | 卸载安装包 |
| download | 下载安装包 |
| list | 列出已安装的包 |
| show | 查看安装包信息 |
| check | 检查安装包依赖 |
| wheel | 通过wheel安装 |
| hash | 计算安装包的hash |
| freeze | 导出requirements |
| completion | 生成自动补全 |
| help | 查看命令的具体帮助 |
查找安装包
➜ Downloads pip help search
Usage:
pip search [options] <query>
Description:
Search for PyPI packages whose name or summary contains <query>.
安装安装包
➜ Downloads pip help install
Usage:
pip install [options] <requirement specifier> [package-index-options] ...
pip install [options] -r <requirements file> [package-index-options] ...
pip install [options] [-e] <vcs project url> ...
pip install [options] [-e] <local project path> ...
pip install [options] <archive url/path> ...
| 选项 | 说明 |
|---|---|
| -r, --requirement < file > | 指定requirements文件 |
| -d, --download < dir > | 下载安装包到指定目录 |
| -U, --upgrade | 更新安装包到最新版 |
| --force-reinstall | 重新安装安装包 |
| -I, --ignore-installed | 重新安装安装包 |
| --no-index | 不到网上查找,和-f搭配使用 |
| -f, --find-links < url > | 指定wheel安装包的查找路径 |
卸载安装包
➜ Downloads pip help uninstall
Usage:
pip uninstall [options] <package> ...
pip uninstall [options] -r <requirements file> ...
| 选项 | 说明 |
|---|---|
| -r, --requirement < file > | 指定requirements文件 |
| -y, --yes | 不需要确认 |
列出安装包
➜ Downloads pip help list
Usage:
pip list [options]
➜ Downloads pip list | grep -i tornado
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
tornado (4.5.2)
tornado-sqlalchemy (0.3.3)
➜ Downloads pip list --format=columns | grep -i tornado
tornado 4.5.2
tornado-sqlalchemy 0.3.3
查看安装包
➜ Downloads pip help show
Usage:
pip show [options] <package> ...
➜ Downloads pip show tornado
Name: tornado
Version: 4.5.2
Summary: Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
Home-page: http://www.tornadoweb.org/
Author: Facebook
Author-email: [email protected]
License: http://www.apache.org/licenses/LICENSE-2.0
Location: /usr/local/lib/python2.7/site-packages
Requires: singledispatch, certifi, backports-abc
➜ Downloads pip show -f tornado | sed -n '1, 13p'
Name: tornado
Version: 4.5.2
Summary: Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
Home-page: http://www.tornadoweb.org/
Author: Facebook
Author-email: [email protected]
License: http://www.apache.org/licenses/LICENSE-2.0
Location: /usr/local/lib/python2.7/site-packages
Requires: singledispatch, certifi, backports-abc
Files:
tornado-4.5.2.dist-info/DESCRIPTION.rst
tornado-4.5.2.dist-info/INSTALLER
tornado-4.5.2.dist-info/METADATA
检查依赖
➜ Downloads pip check
oauth2client 3.0.0 requires pyasn1, which is not installed.
oauth2client 3.0.0 requires rsa, which is not installed.
statsmodels 0.8.0 requires scipy, which is not installed.
patsy 0.4.1 requires numpy, which is not installed.
pandas 0.20.3 requires numpy, which is not installed.
numdifftools 0.9.20 requires numpy, which is not installed.
numdifftools 0.9.20 requires scipy, which is not installed.
matplotlib 2.0.0 requires numpy, which is not installed.
docx 0.2.4 requires lxml, which is not installed.
cryptography 1.5.2 requires pyasn1, which is not installed.
命令补全
➜ Downloads pip completion --zsh
# pip zsh completion start
function _pip_completion {
local words cword
read -Ac words
read -cn cword
reply=( $( COMP_WORDS="$words[*]" \
COMP_CWORD=$(( cword-1 )) \
PIP_AUTO_COMPLETE=1 $words[1] ) )
}
compctl -K _pip_completion pip
# pip zsh completion end
wheel
wheel是新的Python安装包的格式和pip命令,是为了替代eggs
在线安装
pip install wheel
离线安装
pip install wheel-0.30.0-py2.py3-none-any.whl
wheel-0.30.0-py2.py3-none-any.whl需要更换为实际的wheel安装包
使用
➜ Downloads pip help wheel
Usage:
pip wheel [options] <requirement specifier> ...
pip wheel [options] -r <requirements file> ...
pip wheel [options] [-e] <vcs project url> ...
pip wheel [options] [-e] <local project path> ...
pip wheel [options] <archive url/path> ...
| 选项 | 说明 |
|---|---|
| -r, --requirement < file > | 指定requirements文件 |
| -w, --wheel-dir < dir > | wheel包构建和保存目录 |
| --no-index | 不到网上查找,和-f搭配使用 |
| -f, --find-links < url > | 指定wheel安装包的查找路径 |
版本
➜ python git:(master) pip freeze | grep -i tornado
tornado==4.5.2
tornado-sqlalchemy==0.3.3
| 符号 | 说明 |
|---|---|
| == | 限定指定版本 |
| > | 大于指定版本 |
| >= | 大于等于指定版本 |
| < | 小于指定版本 |
| < = | 小于等于指定版本 |
| >< | 排除指定版本 |
注意
<和=之间没有空格,空格是gitbook书写上的问题导致的
参考
Centos 7中安装Python包管理工具——Pip
Python包管理工具——Pip
Python的包管理工具easy_install, setuptools, pip, distribute介绍