pip install 命令详解

pip install 命令用于安装 Python 包,支持从多种源安装包

1. 通过pip install -h命令查看帮助文档

总共包括:

1. usage

2. Description

3. Install Options

4. Package Index Options

5. General Options:

 

1. 用法(usage):

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> ...

 

pip install [选项] <需求说明符> [包索引选项] ...
pip install [选项] -r <需求文件> [包索引选项] ...
pip install [选项] [-e] <VCS 项目 URL> ...
pip install [选项] [-e] <本地项目路径> ...
pip install [选项] <存档 URL/路径> ...

 

说明:

  • <需求说明符>: 指定要安装的包及其版本信息的规范,可以是包名称、版本号、URL 等。
  • <需求文件>: 指定一个包含依赖项规范的文本文件,称为 requirements 文件。
  • <VCS 项目 URL>: 指定要安装的版本控制系统 (VCS) 项目的 URL,如 Git、Mercurial。
  • <本地项目路径>: 指定本地文件系统中的项目路径。
  • <存档 URL/路径>: 指定包的存档文件的 URL 或本地路径。

示例:

1. 从 PyPI 安装包: pip install requests

 2. 从 requirements 文件安装依赖项: pip install -r requirements.txt

3. 从 Git 项目安装包:

pip install -e git+https://github.com/user/repository.git#egg=package_name

4. 从本地项目路径安装: pip install -e /path/to/local/project

5. 从本地存档文件安装: pip install /path/to/archive.tar.gz

总体而言,`pip install` 提供了多种途径来满足安装 Python 包的需求,并可以方便地管理依赖项。确保在执行命令之前理解和满足所需的安装条件。

2. 描述(Description)

Description:
Install packages from:

- PyPI (and other indexes) using requirement specifiers.
- VCS project urls.
- Local project directories.
- Local or remote source archives.

pip also supports installing from "requirements files", which provide an easy way to specify a whole environment to be installed.

说明:

  • <需求说明符>: 指定要安装的包及其版本信息的规范,可以是包名称、版本号、URL 等。
  • <需求文件>: 指定一个包含依赖项规范的文本文件,称为 requirements 文件。
  • <VCS 项目 URL>: 指定要安装的版本控制系统 (VCS) 项目的 URL,如 Git、Mercurial。
  • <本地项目路径>: 指定本地文件系统中的项目路径。
  • <存档 URL/路径>: 指定包的存档文件的 URL 或本地路径。

总体而言,`pip install` 提供了多种途径来满足安装 Python 包的需求,并可以方便地管理依赖项。确保在执行命令之前理解和满足所需的安装条件

 

3. 安装选项(Install Options):

3.1 -r

-r, --requirement <file> Install from the given requirements file. This option can be used multiple times.

从 requirements 文件安装,例如:pip install -r requirements.txt

`-r` 或 `--requirement` 选项用于指定包含依赖关系规范的文件,通常称为 "requirements 文件"。
该选项可以多次使用,每次指定一个 requirements 文件。
通过使用这个选项,你可以一次性安装多个包,而无需逐个列出每个包的名称和版本。

 

详解: `-r <file>` 或 `--requirement <file>`: 指定包含依赖关系规范的文件路径。


示例:

1. 使用单个 requirements 文件: pip install -r requirements.txt

这将安装 `requirements.txt` 文件中列出的所有包及其指定的版本。

2. 使用多个 requirements 文件: pip install -r requirements1.txt -r requirements2.txt

这将安装两个 requirements 文件中列出的所有包及其指定的版本。

3. 在 requirements 文件中,可以使用标准的 pip 包规范来指定每个包的名称和版本要求。例如:
plaintext
# requirements.txt
requests==2.26.0
numpy>=1.21.0,<1.22.0

这个文件中的内容表示安装 `requests` 包的确切版本为 `2.26.0`,而安装 `numpy` 包的版本必须在 `1.21.0` 和 `1.22.0` 之间(不包括 `1.22.0`)。

4. 通过使用 `-r` 选项,`pip` 将会按照 requirements 文件中的规范来安装所有指定的包及其依赖项。

使用 requirements 文件是一种推荐的方式,特别是在项目中管理依赖关系时,可以将所有依赖项集中在一个文件中,以便于维护和分享。

3.2 -c

-c, --constraint <file> Constrain versions using the given constraints file. This option can be used multiple times.

-c--constraint 选项用于通过给定的约束文件来限制包的版本。这个选项可以多次使用,每次指定一个约束文件。约束文件包含了对特定包版本的限制条件,可以确保安装的包符合指定的版本要求。

1. 使用单个约束文件: pip install -c constraints.txt package_name
这将使用 constraints.txt 文件中指定的版本约束来安装 package_name。

2. 使用多个约束文件: pip install -c constraints1.txt -c constraints2.txt package_name
这将使用两个约束文件中指定的版本约束来安装 package_name。

3. 在约束文件中,通常包含对特定包的版本范围的定义,例如:
# constraints.txt
package_name==1.2.3
other_package>=2.0.0,<=3.0.0
这个文件中的内容表示 package_name 的版本必须是精确的 1.2.3,而 other_package 的版本必须在 2.0.0 和 3.0.0 之间(包括这两个版本)。
在使用 -c 选项时,pip 将根据约束文件中的规定来选择符合条件的包版本进行安装。

4. 通过使用约束文件,可以更加灵活地控制包的版本,确保安装的包符合项目的需求和依赖关系。

 

3.3 --no-deps

--no-deps Don't install package dependencies.

 

`--no-deps` 是 `pip install` 命令的一个选项,用于指示 `pip` 在安装包时不安装其依赖项。
通常,`pip` 会自动解析并安装包所依赖的其他包,以确保安装的包能够正常运行。
然而,使用 `--no-deps` 选项将禁止这种自动依赖项安装行为。

详解: --no-deps`: 表示不安装包的依赖项。


示例:

1. pip install --no-deps package_name
在这个示例中,`--no-deps` 选项将阻止 `pip` 安装 `package_name` 的任何依赖项。
这可能会导致所安装的包无法正常运行,因为它可能缺少必要的依赖项。

注意事项:

1. 使用 `--no-deps` 选项时需要小心,确保你了解包的依赖关系,并且明确知道你所安装的包不需要这些依赖项。

2. 在大多数情况下,建议不使用 `--no-deps` 选项,以便 `pip` 可以自动解决并安装所有依赖项,确保软件包的正常运行。

3. 在一些特殊情况下,可能因为系统已经有了一些依赖项而希望跳过依赖项的安装,这时可以考虑使用 `--no-deps` 选项。

3.4 --pre

--pre Include pre-release and development versions. By default, pip only finds stable versions.

`--pre` 是 `pip install` 命令的一个选项,用于指示 `pip` 在安装包时包括预发布版本(pre-release)和开发版本。
默认情况下,`pip` 只会查找稳定版本,即正式发布的版本,而不包括预发布版本或开发版本。

详解: `--pre`: 表示包括预发布版本和开发版本。

示例: pip install --pre package_name

在这个示例中,`--pre` 选项将允许 `pip` 安装 `package_name` 的预发布版本和开发版本,而不仅仅是稳定版本。

注意事项:

1. 预发布版本通常包含最新的功能和改进,但也可能包含一些尚未完全测试或可能不稳定的代码。

2. 在某些情况下,你可能希望安装预发布版本以获取最新的功能或修复某些问题,但请注意这可能会引入潜在的不稳定性。

3. 如果你只想安装稳定版本,可以省略 `--pre` 选项。

4. 这个选项在开发环境或测试新特性时非常有用,但在生产环境中需要谨慎使用。

3.5 -e

-e, --editable <path/url> Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.

`-e` 或 `--editable` 是 `pip install` 命令的一个选项,用于以可编辑模式(editable mode)安装项目。
可编辑模式通常被称为 setuptools 的 "develop mode",它允许你在本地进行开发,并在修改代码后立即看到变化,而不需要重新安装包。

详解:`-e <path/url>` 或 `--editable <path/url>`: 指定项目的本地路径或版本控制系统 (VCS) 的 URL。可以是本地文件系统中的路径,也可以是版本控制系统的 URL。

示例:

1. 从本地项目路径安装: pip install -e /path/to/local/project

这将以可编辑模式安装指定路径中的项目。

2. 从 Git 仓库安装:

pip install -e git+https://github.com/user/repository.git#egg=package_name

这将以可编辑模式安装指定的 Git 仓库。

可编辑模式的效果:

1.在可编辑模式下安装的包实际上是对项目源代码的符号链接,而不是复制文件到 Python 安装目录。

2. 这意味着你可以直接在项目源代码中进行更改,并且这些更改会立即反映在你的 Python 环境中,无需重新安装。

3. 这对于在开发过程中进行实时调试和测试非常有用。


注意事项:

1. 可编辑模式适用于开发环境,但不适用于在生产环境中部署代码。

2. 在可编辑模式下安装的包可能会影响到你的 Python 环境的其他项目,因此需要小心使用。

使用可编辑模式时,确保理解其工作原理,以及在何种情况下使用它是合适的。

 

3.6 --dry-run


--dry-run Don't actually install anything, just print what would be. Can be used in combination with --ignore-installed to 'resolve' the requirements.

`--dry-run` 是 `pip install` 命令的一个选项,用于在不实际安装任何内容的情况下,仅打印出安装的过程。
这可以用于检查安装过程中可能发生的情况,而不实际修改你的 Python 环境。

详解: `--dry-run`: 表示不实际安装,只是打印出将要安装的内容。


示例:

1. pip install --dry-run package_name

在这个示例中,`--dry-run` 选项将展示安装 `package_name` 时会发生什么,但并不会实际进行安装。
这对于在安装包之前查看依赖项或检查版本冲突等情况非常有用。


2. 与 `--ignore-installed` 结合使用:
pip install --dry-run --ignore-installed package_name

结合使用 `--dry-run` 和 `--ignore-installed` 选项,可以在不考虑已安装的包的情况下,检查将要安装的内容。
这对于解决依赖关系或检查新版本是否符合要求等情况非常有用。

注意事项:

1. `--dry-run` 是一个只读操作,不会对系统进行实际的修改。
2. 使用 `--dry-run` 时,`pip` 会模拟安装过程,但不会实际执行任何复制文件或修改系统的操作。
3. 该选项对于验证将要进行的操作以及检查潜在问题非常有用,特别是在进行重要操作之前。

3.7 -t

-t, --target <dir> Install packages into <dir>. By default this will not replace existing files/folders in <dir>. Use --upgrade to replace existing packages in <dir> with new

versions.

`-t` 或 `--target` 是 `pip install` 命令的一个选项,用于指定将包安装到的目标目录。
默认情况下,该目录不会替换已存在的文件或文件夹,如果需要替换现有的包版本,可以结合使用 `--upgrade` 选项。

详解:

- `-t <dir>` 或 `--target <dir>`: 指定包的安装目标目录。

示例:

1. 安装到指定目录:

pip install -t /path/to/target/directory package_name

这将把 `package_name` 安装到指定的目录 `/path/to/target/directory`。

2. 替换已存在的包:

pip install -t /path/to/target/directory --upgrade package_name

使用 `--upgrade` 选项,可以替换指定目录中已存在的同名包,以安装新版本。

注意事项:

- `-t` 选项通常在你想要将包安装到特定目录而不是默认目录时使用。这对于将包安装到项目特定的文件夹或构建系统的临时目录中非常有用。

- 如果不使用 `-t` 选项,则包将被安装到 Python 默认的安装目录。

- 使用 `--upgrade` 选项时要小心,确保你真的想要替换目标目录中的现有包版本。

- 可以结合使用其他选项,例如 `--no-deps`、`--ignore-installed` 等,以根据需求更灵活地安装和管理包。

 

3.8 --platform

--platform <platform> Only use wheels compatible with <platform>. Defaults to the platform of the running system. Use this option multiple times to specify multiple platforms

supported by the target interpreter.

`--platform` 是 `pip install` 命令的一个选项,用于指定仅使用与指定平台兼容的 wheel 文件进行安装。默认情况下,`pip` 会选择与运行系统平台兼容的 wheel 文件进行安装。

详解:

- `--platform <platform>`: 指定要使用的平台。可以是操作系统名称、版本和体系结构的组合。默认为运行系统的平台。

- 这个选项可以多次使用,以指定多个目标平台,`pip` 将会选择与这些平台中的任何一个兼容的 wheel 文件进行安装。

示例:

1. 指定特定平台:

pip install --platform linux_x86_64 package_name

这将安装与 `linux_x86_64` 平台兼容的 wheel 文件。

2. 指定多个平台:

pip install --platform linux_x86_64 --platform macosx_10_14_x86_64 package_name

这将安装与 `linux_x86_64` 和 `macosx_10_14_x86_64` 平台兼容的 wheel 文件。

注意事项:

- 指定平台的格式通常是 `<os>_<version>_<arch>`,例如 `linux_x86_64` 表示 Linux 平台的 64 位版本。

- 通过指定平台,你可以确保安装的 wheel 文件与目标系统兼容,以避免可能的兼容性问题。

- 默认情况下,`--platform` 的值与运行 `pip install` 命令的系统平台相同,因此通常不需要手动指定。

- 该选项对于在特定平台上交叉编译或在虚拟环境中安装特定平台的 wheel 文件非常有用。

确保在使用 `--platform` 选项时了解目标平台的正确格式,并根据需要选择适当的值。

 

3.9 --python-version


--python-version <python_version>
The Python interpreter version to use for wheel and "Requires-Python" compatibility checks. Defaults to a version derived from the running interpreter. The
version can be specified using up to three dot-separated integers (e.g. "3" for 3.0.0, "3.7" for 3.7.0, or "3.7.3"). A major-minor version can also be given
as a string without dots (e.g. "37" for 3.7.0).

`--python-version` 是 `pip install` 命令的一个选项,用于指定用于 wheel 文件和 "Requires-Python" 兼容性检查的 Python 解释器版本。默认情况下,该选项使用从运行解释器派生的版本。

详解:

- `--python-version <python_version>`: 指定用于 wheel 文件和 "Requires-Python" 兼容性检查的 Python 解释器版本。

- 版本可以使用最多三个点分隔的整数表示(例如 "3" 表示 3.0.0,"3.7" 表示 3.7.0,或 "3.7.3")。也可以将主次版本号表示为没有点的字符串(例如 "37" 表示 3.7.0)。

示例:

1. 指定具体版本:

pip install --python-version 3.8 package_name

这将使用 Python 3.8 版本进行兼容性检查和安装。

2. 指定主次版本号:

pip install --python-version 37 package_name

这将使用 Python 3.7 版本进行兼容性检查和安装。

注意事项:

- 通过指定 Python 解释器版本,可以确保安装的 wheel 文件与指定的 Python 版本兼容,以避免可能的兼容性问题。

- 默认情况下,`--python-version` 的值与运行 `pip install` 命令的系统的 Python 版本相同,因此通常不需要手动指定。

- 在一些情况下,可能需要在不同版本的 Python 环境中安装包,这时可以使用 `--python-version` 选项来指定目标版本。

 

3.10 --implementation

--implementation <implementation>

Only use wheels compatible with Python implementation <implementation>, e.g. 'pp', 'jy', 'cp', or 'ip'. If not specified, then the current interpreter
implementation is used. Use 'py' to force implementation-agnostic wheels.

 

`--implementation` 是 `pip install` 命令的一个选项,用于指定只使用与指定 Python 实现兼容的 wheel 文件进行安装。如果未指定,则使用当前解释器的实现。可以使用 `'py'` 来强制使用与实现无关的 wheel 文件。

详解:

- `--implementation <implementation>`: 指定要使用的 Python 实现。有效的选项包括 `'pp'`(PyPy)、`'jy'`(Jython)、`'cp'`(CPython,即标准的 CPython 解释器)或 `'ip'`(IronPython)。使用 `'py'` 选项可以强制使用与实现无关的 wheel 文件。

示例:

1. 指定使用 PyPy:

pip install --implementation pp package_name

这将只使用 PyPy 兼容的 wheel 文件进行安装。

2. 指定使用 CPython:

pip install --implementation cp package_name

这将只使用 CPython 兼容的 wheel 文件进行安装。

3. 强制使用与实现无关的 wheel:

pip install --implementation py package_name

这将强制使用与实现无关的 wheel 文件进行安装,适用于任何 Python 实现。

注意事项:

- 通过指定 Python 实现,可以确保安装的 wheel 文件与指定的实现兼容,以避免可能的兼容性问题。

- 默认情况下,`--implementation` 的值与运行 `pip install` 命令的系统的 Python 实现相同,因此通常不需要手动指定。

- 在一些情况下,可能需要在不同的 Python 实现中安装包,这时可以使用 `--implementation` 选项来指定目标实现。

3.11 --abi


--abi <abi> Only use wheels compatible with Python abi <abi>, e.g. 'pypy_41'. If not specified, then the current interpreter abi tag is used. Use this option multiple
times to specify multiple abis supported by the target interpreter. Generally you will need to specify --implementation, --platform, and --python-version
when using this option.

`--abi` 是 `pip install` 命令的一个选项,用于指定只使用与指定 Python ABI(Application Binary Interface) 兼容的 wheel 文件进行安装。如果未指定,则使用当前解释器的 ABI 标签。可以使用 `--abi` 选项多次指定目标解释器支持的多个 ABI。

详解:

- `--abi <abi>`: 指定要使用的 Python ABI。ABI 是二进制接口的缩写,描述了二进制对象文件(如共享库或 DLL)在编译和运行时的接口。典型的 ABI 标签如 `'pypy_41'`。

- 这个选项可以多次使用,以指定目标解释器支持的多个 ABI。通常,在使用这个选项时,还需要指定 `--implementation`、`--platform` 和 `--python-version`。

示例:

1. 指定使用 PyPy 4.1 的 ABI:

pip install --abi pypy_41 package_name

这将只使用 PyPy 4.1 的 ABI 兼容的 wheel 文件进行安装。

2. 指定多个 ABI:

pip install --abi pypy_41 --abi pypy_42 package_name

这将只使用 PyPy 4.1 和 PyPy 4.2 的 ABI 兼容的 wheel 文件进行安装。

注意事项:

- 通过指定 Python ABI,可以确保安装的 wheel 文件与指定的 ABI 兼容,以避免可能的兼容性问题。

- 默认情况下,`--abi` 的值与运行 `pip install` 命令的系统的 Python ABI 相同,因此通常不需要手动指定。

- 在一些情况下,可能需要在不同 ABI 版本的 Python 环境中安装包,这时可以使用 `--abi` 选项来指定目标 ABI。

 

3.12  --user


--user Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on Windows. (See the Python documentation for
site.USER_BASE for full details.)

`--user` 是 `pip install` 命令的一个选项,用于将包安装到用户特定的目录,而不是系统范围的目录。这样可以在没有管理员权限的情况下安装包。

详解:

- `--user`: 表示将包安装到用户特定的目录,而不是系统范围的目录。

示例:


pip install --user package_name


在这个示例中,`--user` 选项将 `package_name` 安装到用户的特定目录中。

安装目录:

- 在 Linux 和 macOS 系统上,通常安装到 `~/.local/` 目录。

- 在 Windows 系统上,通常安装到 `%APPDATA%\Python` 目录。

注意事项:

- 使用 `--user` 选项时,安装的包只对当前用户可见,不会影响系统范围的 Python 安装。

- 这对于在没有管理员权限的环境中安装包非常有用,例如在共享主机或虚拟环境中。

- 如果没有指定 `--user` 选项,默认情况下 `pip` 会尝试将包安装到系统范围的目录中,可能需要管理员权限。

- 确保了解用户特定安装目录的结构,以便理解在哪里可以找到安装的包。

 

3.13 --root


--root <dir> Install everything relative to this alternate root directory.

`--root` 是 `pip install` 命令的一个选项,用于指定安装所有内容的根目录。这使得你可以在指定的根目录中创建与 Python 安装目录相似的目录结构,而不是直接安装到系统的 Python 目录。

**详解:**

- `--root <dir>`: 指定一个替代的根目录,安装所有内容相对于这个目录。

**示例:**

```bash
pip install --root /path/to/installation/root package_name
```

在这个示例中,`--root` 选项将 `package_name` 安装到指定的 `/path/to/installation/root` 目录中。

**安装目录结构:**

- 安装包的二进制文件、库和脚本将被放置在 `/path/to/installation/root/` 目录下的相应子目录中,类似于 Python 安装目录的结构。

**注意事项:**

- 使用 `--root` 选项时,安装的包将不会直接安装到系统范围的 Python 目录,而是相对于指定的根目录。

- 这对于在没有管理员权限的情况下在自定义目录中安装包很有用,例如在虚拟环境中。

- 在使用 `--root` 选项时,需要确保目标目录具有适当的权限,并且可以由用户写入。

- 使用 `--root` 选项后,通常需要手动添加相应的路径到系统的 `PATH` 环境变量中,以便可以在命令行中执行安装的脚本和可执行文件。

 

3.14 --prefix


--prefix <dir> Installation prefix where lib, bin and other top-level folders are placed. Note that the resulting installation may contain scripts and other resources which
reference the Python interpreter of pip, and not that of ``--prefix``. See also the ``--python`` option if the intention is to install packages into another
(possibly pip-free) environment.

`--prefix` 是 `pip install` 命令的一个选项,用于指定安装的前缀(prefix)目录,该目录包含顶级文件夹,如 `lib`、`bin` 等。这允许你在指定的前缀目录下创建类似于 Python 安装目录的结构。

**详解:**

- `--prefix <dir>`: 指定安装的前缀目录。

**示例:**

```bash
pip install --prefix /path/to/installation/prefix package_name
```

在这个示例中,`--prefix` 选项将 `package_name` 安装到指定的 `/path/to/installation/prefix` 目录中。

**安装目录结构:**

- 安装包的二进制文件、库和脚本将被放置在 `/path/to/installation/prefix/` 目录下的相应子目录中,类似于 Python 安装目录的结构。

**注意事项:**

- 使用 `--prefix` 选项时,安装的包将不会直接安装到系统范围的 Python 目录,而是相对于指定的前缀目录。

- 这对于在没有管理员权限的情况下在自定义目录中安装包很有用,例如在虚拟环境中。

- 在使用 `--prefix` 选项时,需要确保目标目录具有适当的权限,并且可以由用户写入。

- 使用 `--prefix` 选项后,通常需要手动添加相应的路径到系统的 `PATH` 环境变量中,以便可以在命令行中执行安装的脚本和可执行文件。

- 注意,安装的脚本和其他资源可能引用 `pip` 的 Python 解释器,而不是指定 `--prefix` 时的 Python 解释器。如果需要将包安装到另一个环境,请考虑使用 `--python` 选项。

 

3.15 --src


--src <dir> Directory to check out editable projects into. The default in a virtualenv is "<venv path>/src". The default for global installs is "<current dir>/src".

`--src` 是 `pip install` 命令的一个选项,用于指定可编辑项目(editable projects)的检出目录。在默认情况下,虚拟环境中的可编辑项目将被检出到 `<venv path>/src`,而全局安装则会将其检出到 `<current dir>/src`。

**详解:**

- `--src <dir>`: 指定可编辑项目的检出目录。

**示例:**

```bash
pip install -e --src /path/to/checkout/directory project_name
```

在这个示例中,`-e` 表示安装可编辑项目,而 `--src` 选项将项目检出到指定的 `/path/to/checkout/directory` 目录中。

**默认目录:**

- 在虚拟环境中,默认的可编辑项目检出目录是 `<venv path>/src`。

- 在全局安装中,默认的可编辑项目检出目录是 `<current dir>/src`。

**注意事项:**

- 可编辑项目是一种安装模式,允许在源代码的当前开发目录中进行开发,并使对源代码的更改立即生效。

- 使用 `--src` 选项可以指定可编辑项目的检出目录,使其更容易找到和管理。

- 如果没有指定 `--src` 选项,`pip` 将使用默认的检出目录。

- 该选项对于在多个项目之间切换或同时开发多个项目非常有用。

3.16 -U

  -U, --upgrade               Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.

 

3.17  --upgrade-strategy 


--upgrade-strategy <upgrade_strategy>

Determines how dependency upgrading should be handled [default: only-if-needed]. "eager" - dependencies are upgraded regardless of whether the currently
installed version satisfies the requirements of the upgraded package(s). "only-if-needed" - are upgraded only when they do not satisfy the requirements of
the upgraded package(s).

 

3.18 --force-reinstall 


--force-reinstall Reinstall all packages even if they are already up-to-date.

 

 

3.19 -I


-I, --ignore-installed Ignore the installed packages, overwriting them. This can break your system if the existing package is of a different version or was installed with a
different package manager!

 

 

3.20 --ignore-requires-python


--ignore-requires-python Ignore the Requires-Python information.

 

3.21  --no-build-isolation

--no-build-isolation Disable isolation when building a modern source distribution. Build dependencies specified by PEP 518 must be already installed if this option is used.

 

3.22 --use-pep517

--use-pep517 Use PEP 517 for building source distributions (use --no-use-pep517 to force legacy behaviour).

 

3.23 --check-build-dependencies


--check-build-dependencies Check the build dependencies when PEP517 is used.

 

3.24 --break-system-packages 


--break-system-packages Allow pip to modify an EXTERNALLY-MANAGED Python installation

 

3.25 -C


-C, --config-settings <settings>
Configuration settings to be passed to the PEP 517 build backend. Settings take the form KEY=VALUE. Use multiple --config-settings options to pass multiple
keys to the backend.

 

 

3.26 --global-option


--global-option <options> Extra global options to be supplied to the setup.py call before the install or bdist_wheel command.

 

3.27 --compile


--compile Compile Python source files to bytecode

 

3.28 --no-compile


--no-compile Do not compile Python source files to bytecode

 

 3.29 --no-warn-script-location


--no-warn-script-location Do not warn when installing scripts outside PATH

 3.30 --no-warn-conflicts

--no-warn-conflicts Do not warn about broken dependencies

 

3.31 --no-binary

--no-binary <format_control>
Do not use binary packages. Can be supplied multiple times, and each time adds to the existing value. Accepts either ":all:" to disable all binary packages,
":none:" to empty the set (notice the colons), or one or more package names with commas between them (no colons). Note that some packages are tricky to
compile and may fail to install when this option is used on them.

 

3.32 --only-binary


--only-binary <format_control>
Do not use source packages. Can be supplied multiple times, and each time adds to the existing value. Accepts either ":all:" to disable all source packages,
":none:" to empty the set, or one or more package names with commas between them. Packages without binary distributions will fail to install when this option
is used on them.

 

3.33 --prefer-binary


--prefer-binary Prefer binary packages over source packages, even if the source packages are newer.

 

3.34 --require-hashes


--require-hashes Require a hash to check each requirement against, for repeatable installs. This option is implied when any package in a requirements file has a --hash
option.

 

3.35 --progress-bar


--progress-bar <progress_bar>
Specify whether the progress bar should be used [on, off] (default: on)

 

 

3.36 --root-user-action


--root-user-action <root_user_action>
Action if pip is run as a root user. By default, a warning message is shown.

 

3.37  --report 

 

--report <file> Generate a JSON file describing what pip did to install the provided requirements. Can be used in combination with --dry-run and --ignore-installed to
'resolve' the requirements. When - is used as file name it writes to stdout. When writing to stdout, please combine with the --quiet option to avoid mixing
pip logging output with JSON output.

 

3.38 --no-clean

--no-clean Don't clean up build directories.

 

4. 配置软件包索引选项:

Package Index Options:

4.1 -i

-i, --index-url <url> Base URL of the Python Package Index (default https://pypi.tuna.tsinghua.edu.cn/simple/). This should point to a repository compliant with PEP 503 (the

simple repository API) or a local directory laid out in the same format.

 

 

4.2 --extra-index-url


--extra-index-url <url> Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules as --index-url.

 

 

4.3 --no-index

--no-index Ignore package index (only looking at --find-links URLs instead).

 

4.4 -f 

-f, --find-links <url> If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path or file:// URL that's a

directory, then look for archives in the directory listing. Links to VCS project URLs are not supported.

 

 

5. 通用选项

General Options:

5.1 -h


-h, --help Show help.

查看帮助文档

 

5.2  --debug 


--debug Let unhandled exceptions propagate outside the main subroutine, instead of logging them to stderr.

 允许未处理的异常传播到主程序之外,而不是将它们记录到 stderr。

pip --debug install SomePackage

 

5.3 --isolated


--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.

 在隔离模式下运行 pip,忽略环境变量和用户配置。

pip --isolated install SomePackage

 

5.4 --require-virtualenv


--require-virtualenv Allow pip to only run in a virtual environment; exit with an error otherwise.

 允许 pip 只在虚拟环境中运行;否则退出并显示错误。

pip --require-virtualenv install SomePackage

 

5.5 --python 

--python <python> Run pip with the specified Python interpreter.

 使用指定的 Python 解释器运行 pip

pip --python /path/to/python3.8 install SomePackage

 

4.6 -v


-v, --verbose Give more output. Option is additive, and can be used up to 3 times.

提供更多输出,可以叠加使用多次(最多3次)。

pip -vvv install SomePackage

 

4.7 -V


-V, --version Show version and exit.

显示版本信息后退出

 

 

4.8 -q


-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).

 

 

4.9  --log 

--log <path>                Path to a verbose appending log.

  

4.10  --no-input


--no-input Disable prompting for input.

 

 

4.11 --keyring-provider


--keyring-provider <keyring_provider>
Enable the credential lookup via the keyring library if user input is allowed. Specify which mechanism to use [disabled, import, subprocess]. (default:
disabled)

 

 

4.12 --proxy

 --proxy <proxy> Specify a proxy in the form scheme://[user:passwd@]proxy.server:port.

 

4.13 --retries

--retries <retries> Maximum number of retries each connection should attempt (default 5 times).

 

4.14  --timeout 


--timeout <sec> Set the socket timeout (default 15 seconds).

 

4.15 --exists-action


--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.

 

 

4.16 --trusted-host


--trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.

 

4.17 --cert 


--cert <path> Path to PEM-encoded CA certificate bundle. If provided, overrides the default. See 'SSL Certificate Verification' in pip documentation for more information.

 

4.18 --client-cert


--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.

 

4.19 --cache-dir


--cache-dir <dir> Store the cache data in <dir>.

 

4.20 --no-cache-dir


--no-cache-dir Disable the cache.

 

 

4.21 --disable-pip-version-check


--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.

 

4.22 --no-color


--no-color Suppress colored output.

 

 

4.23 --no-python-version-warning


--no-python-version-warning
Silence deprecation warnings for upcoming unsupported Pythons.

 

4.24 --use-feature 

--use-feature <feature> Enable new functionality, that may be backward incompatible.

 

4.25 --use-deprecated 


--use-deprecated <feature> Enable deprecated functionality, that will be removed in the future.

 

posted @ 2024-02-23 22:28  Allen_Hao  阅读(8168)  评论(0编辑  收藏  举报