- 前言
- 1 用法
- 2 安装位置
- 3 安装步骤
- 4 参数处理顺序
- 5 运行时依赖项的安装顺序
- 6 Requirements File Format
- 7 博文推荐
- 总结
前言
提示:这里可以添加本文要记录的大概内容:
越来越感觉到有必要掌握 pip install 命令行,所以我就学习了 pip 参考手册。本文是对该参考手册的摘抄和再整理,也记录了自己使用该命令行的过程。
提示:以下是本篇文章正文内容,下面案例可供参考
1 用法py -m pip install [options][package-index-options] ... py -m pip install [options] -r [package-index-options] ... py -m pip install [options] [-e] ... py -m pip install [options] [-e] ... py -m pip install [options] ...
2 安装位置
- PyPI(和其他索引)使用需求说明符。
- VCS 项目网址。
- 本地项目目录。
- 本地或远程源档案。
- 从“需求文件”(“requirements files”)安装,这提供了一种简单的方法来指定要安装的整个环境。
3 安装步骤
- 确定基本要求。用户提供的参数在此处处理。
- 解决依赖关系。将在此处确定要安装的内容。
- 造轮子。所有可以构建的依赖项都内置在轮子中。Build wheels. All the dependencies that can be are built into wheels.
- 安装软件包(并卸载任何正在升级/替换的东西)。
- 除非指定了 --upgrade,否则 pip install 倾向于保持已安装的版本不变。
4 参数处理顺序
- 项目或存档 URL。
- 本地目录(必须包含setup.py,否则 pip 会报错)。
- 本地文件(sdist 或 wheel 格式存档,遵循这些格式的命名约定)。
- 以上要求都添加到安装要满足的 requirements 中。
5 运行时依赖项的安装顺序
如果 quux 依赖于 foo,而后者又依赖于 bar,而 bar 又依赖于 baz,而后者又依赖于 foo:
>>> C:> py -m pip install quux # Installing collected packages baz, bar, foo, quux ... >>> C:> py -m pip install bar # Installing collected packages foo, baz, bar ...
6 Requirements File Format
-
使用这种格式的文件通常称为“pip requirements.txt 文件”,因为requirements.txt这些文件通常是这样命名的(尽管这不是必需的)。
-
需求文件的每一行都指示要安装的东西,或pip install的参数。支持以下形式:
[[--option]...][-e] [-e]
- Global options
# The following options have an effect on the entire pip install run, and must be # specified on their individual lines. -i, --index-url --extra-index-url --no-index -c, --constraint -r, --requirement -e, --editable -f, --find-links --no-binary --only-binary --prefer-binary --require-hashes --pre --trusted-host --use-feature
7 博文推荐
- pip 的下载、安装及多种命令行列举
值得学习的部分是:用 pip-review 批量更新包,以及对镜像地址的临时使用或永久更改
总结
pip install 并不是一个简单的命令行,因为常常遇到这样的情况:安装了一个包,结果缺少依赖的其他包。值得好好学习!



