安装软件包

Installing Packages

本节介绍了如何安装 Python 的基础知识。

需要注意的是,在此上下文中,“包(package)”一词用于描述一个软件包(即作为 distribution 的同义词)进行安装。它并不指你在 Python 源代码中导入的 ,而不常使用“distribution”一词,因为它容易与 Linux 发行版或其他更大规模的软件发行版(如 Python 本身)混淆。

This section covers the basics of how to install Python packages.

It's important to note that the term "package" in this context is being used to describe a bundle of software to be installed (i.e. as a synonym for a distribution). It does not refer to the kind of package that you import in your Python source code (i.e. a container of modules). It is common in the Python community to refer to a distribution using the term "package". Using the term "distribution" is often not preferred, because it can easily be confused with a Linux distribution, or another larger software distribution like Python itself.

安装软件包的要求

Requirements for Installing Packages

本节介绍安装其他 Python 包之前要遵循的步骤。

This section describes the steps to follow before installing other Python packages.

确保您可以从命令行运行 Python

Ensure you can run Python from the command line

在继续之前,请确保你已经安装了 Python,并且可以在命令行中访问到期望的版本。你可以通过运行以下命令来检查:

python3 --version
py --version

你应该看到类似 Python 3.6.3 的输出。如果你没有安装 Python,请从 python.org 安装最新的 3.x 版本,或者参考《Python 新手指南》中 安装 Python 部分。

备注

如果你是新手,并且遇到类似以下错误:

>>> python3 --version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python3' is not defined

这是因为这个命令以及本教程中其他推荐的命令是设计为在 shell*(也称为 *terminalconsole)中运行的。有关使用操作系统 shell 并与 Python 交互的介绍,请参阅 Python 新手 `入门教程`_

备注

如果你正在使用增强型 shell,如 IPython 或 Jupyter notebook,你可以通过在命令前加上 ! 来运行本教程中的系统命令:

In [1]: import sys
        !{sys.executable} --version
Python 3.6.3

推荐使用 {sys.executable} 而不是直接使用 python ,这样可以确保命令在当前运行的 notebook 所匹配的 Python 安装中执行(这可能不同于 python 命令所指的 Python 安装)。

备注

由于大多数 Linux 发行版处理 Python 3 迁移的方式,使用系统 Python 而没有先创建虚拟环境的 Linux 用户,应该将本教程中的 python 命令替换为 python3,并将 python -m pip 命令替换为 python3 -m pip --user。请不要使用 sudo 运行本教程中的任何命令:如果你遇到权限错误,请返回到创建虚拟环境的部分,先设置一个虚拟环境,然后按照教程继续进行。

Before you go any further, make sure you have Python and that the expected version is available from your command line. You can check this by running:

python3 --version
py --version

You should get some output like Python 3.6.3. If you do not have Python, please install the latest 3.x version from python.org or refer to the Installing Python section of the Hitchhiker's Guide to Python.

备注

If you're a newcomer and you get an error like this:

>>> python3 --version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python3' is not defined

It's because this command and other suggested commands in this tutorial are intended to be run in a shell (also called a terminal or console). See the Python for Beginners getting started tutorial for an introduction to using your operating system's shell and interacting with Python.

备注

If you're using an enhanced shell like IPython or the Jupyter

notebook, you can run system commands like those in this tutorial by prefacing them with a ! character:

In [1]: import sys
        !{sys.executable} --version
Python 3.6.3

It's recommended to write {sys.executable} rather than plain python in order to ensure that commands are run in the Python installation matching the currently running notebook (which may not be the same Python installation that the python command refers to).

备注

Due to the way most Linux distributions are handling the Python 3

migration, Linux users using the system Python without creating a virtual environment first should replace the python command in this tutorial with python3 and the python -m pip command with python3 -m pip --user. Do not run any of the commands in this tutorial with sudo: if you get a permissions error, come back to the section on creating virtual environments, set one up, and then continue with the tutorial as written.

确保您可以从命令行运行 pip

Ensure you can run pip from the command line

此外,你还需要确保 pip 可用。你可以通过运行以下命令来检查:

python3 -m pip --version
py -m pip --version

如果你是从源代码安装 Python,或者使用 python.org 提供的安装程序,或通过 Homebrew 安装的,那么你应该已经有了 pip。如果你使用 Linux,并且是通过操作系统的包管理器安装的,你可能需要单独安装 pip,参见 使用 Linux 包管理器安装 pip/setuptools/wheel

如果 pip 尚未安装,可以先尝试从标准库中引导安装:

python3 -m ensurepip --default-pip
py -m ensurepip --default-pip

如果这仍然无法让你运行 python -m pip,可以按照以下步骤操作:

  • 安全下载 get-pip.py [1]

  • 运行 python get-pip.py[2] 这将安装或升级 pip。同时,如果没有安装,它还会安装 Setuptoolswheel

警告

如果你使用的是由操作系统或其他包管理器管理的 Python 安装,请小心。get-pip.py 不会与这些工具协调,可能会导致系统处于不一致的状态。你可以使用 python get-pip.py --prefix=/usr/local/ 将其安装到 /usr/local,这是为本地安装的软件设计的路径。

Additionally, you'll need to make sure you have pip available. You can check this by running:

python3 -m pip --version
py -m pip --version

If you installed Python from source, with an installer from python.org, or via Homebrew you should already have pip. If you're on Linux and installed using your OS package manager, you may have to install pip separately, see 使用 Linux 包管理器安装 pip/setuptools/wheel.

If pip isn't already installed, then first try to bootstrap it from the standard library:

python3 -m ensurepip --default-pip
py -m ensurepip --default-pip

If that still doesn't allow you to run python -m pip:

  • Securely Download get-pip.py [1]

  • Run python get-pip.py. [2] This will install or upgrade pip. Additionally, it will install Setuptools and wheel if they're not installed already.

警告

Be cautious if you're using a Python install that's managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. You can use python get-pip.py --prefix=/usr/local/ to install in /usr/local which is designed for locally-installed software.

确保 pip、setuptools 和 wheel 是最新的

Ensure pip, setuptools, and wheel are up to date

虽然仅使用 pip 就足够从预构建的二进制档案安装软件,但为了确保你也能从源代码档案安装,保持最新版本的 setuptoolswheel 项目是非常有用的:

python3 -m pip install --upgrade pip setuptools wheel
py -m pip install --upgrade pip setuptools wheel

While pip alone is sufficient to install from pre-built binary archives, up to date copies of the setuptools and wheel projects are useful to ensure you can also install from source archives:

python3 -m pip install --upgrade pip setuptools wheel
py -m pip install --upgrade pip setuptools wheel

(可选)创建虚拟环境

Optionally, create a virtual environment

有关详细信息,请参阅下文的 部分,但这是在典型的 Linux 系统上使用的基本 venv [3] 命令:

python3 -m venv tutorial_env
source tutorial_env/bin/activate
py -m venv tutorial_env
tutorial_env\Scripts\activate

这将会在 tutorial_env 子目录中创建一个新的虚拟环境,并将当前 shell 配置为使用该环境作为默认的 python 环境。

See section below for details, but here's the basic venv [3] command to use on a typical Linux system:

python3 -m venv tutorial_env
source tutorial_env/bin/activate
py -m venv tutorial_env
tutorial_env\Scripts\activate

This will create a new virtual environment in the tutorial_env subdirectory, and configure the current shell to use it as the default python environment.

创建虚拟环境

Creating Virtual Environments

Python "虚拟环境" 允许将 Python 安装到特定应用程序的隔离位置,而不是全局安装。如果你希望安全地安装全局命令行工具,请参阅 安装独立的命令行工具

想象一下,你有一个应用程序需要版本 1 的 LibFoo,而另一个应用程序需要版本 2。你如何同时使用这两个应用程序?如果你将所有内容安装到 /usr/lib/python3.6/site-packages (或你平台的标准位置),很容易陷入一个情况,不小心升级了一个不应该升级的应用程序。

或者更普遍地,假设你想安装一个应用程序并保持不变。如果一个应用程序已经正常工作,那么它的库或库版本的任何变化都可能会导致应用程序崩溃。

还有,如果你不能将 安装到全局的 site-packages 目录呢?例如,在共享主机上。

在所有这些情况下,虚拟环境都可以帮助你。它们有自己的安装目录,不与其他虚拟环境共享库。

目前,有两个常见的工具用于创建 Python 虚拟环境:

  • venv 从 Python 3.3 及更高版本开始默认可用,并且会在创建的虚拟环境中安装 pip (Python 3.4 及更高版本),(Python 3.12 之前的版本还会安装 Setuptools )。

  • virtualenv 需要单独安装,但支持 Python 2.7+ 和 Python 3.3+,并且默认情况下会将 pipSetuptoolswheel 安装到创建的虚拟环境中(不管 Python 版本如何)。

基本用法如下:

使用 venv

python3 -m venv <DIR>
source <DIR>/bin/activate
py -m venv <DIR>
<DIR>\Scripts\activate

使用 virtualenv

python3 -m virtualenv <DIR>
source <DIR>/bin/activate
virtualenv <DIR>
<DIR>\Scripts\activate

有关更多信息,请参阅 venv 文档或 virtualenv 文档。

在 Unix shell 下使用 source 命令可以确保虚拟环境的变量设置在当前 shell 中,而不是在子进程中(子进程会消失,没有任何有用的效果)。

在上述两种情况下,Windows 用户 不应 使用 source 命令,而应该直接从命令行运行 activate 脚本,如下所示:

<DIR>\Scripts\activate

直接管理多个虚拟环境可能会变得繁琐,因此 依赖管理教程 介绍了一个更高层次的工具 Pipenv,它可以自动为你正在使用的每个项目和应用程序管理一个独立的虚拟环境。

Python "Virtual Environments" allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally. If you are looking to safely install global command line tools, see 安装独立的命令行工具.

Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python3.6/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.

Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtual environments can help you. They have their own installation directories and they don’t share libraries with other virtual environments.

Currently, there are two common tools for creating Python virtual environments:

  • venv is available by default in Python 3.3 and later, and installs

pip into created virtual environments in Python 3.4 and later (Python versions prior to 3.12 also installed Setuptools). * virtualenv needs to be installed separately, but supports Python 2.7+ and Python 3.3+, and pip, Setuptools and wheel are always installed into created virtual environments by default (regardless of Python version).

The basic usage is like so:

Using venv:

python3 -m venv <DIR>
source <DIR>/bin/activate
py -m venv <DIR>
<DIR>\Scripts\activate

Using virtualenv:

python3 -m virtualenv <DIR>
source <DIR>/bin/activate
virtualenv <DIR>
<DIR>\Scripts\activate

For more information, see the venv docs or the virtualenv docs.

The use of source under Unix shells ensures that the virtual environment's variables are set within the current shell, and not in a subprocess (which then disappears, having no useful effect).

In both of the above cases, Windows users should not use the source command, but should rather run the activate script directly from the command shell like so:


<DIR>Scriptsactivate

Managing multiple virtual environments directly can become tedious, so the dependency management tutorial introduces a higher level tool, Pipenv, that automatically manages a separate virtual environment for each project and application that you work on.

使用 pip 进行安装

Use pip for Installing

pip 是推荐的安装工具。下面,我们将介绍最常见的使用场景。有关更多详细信息,请参阅 pip 文档,其中包括完整的 参考指南

pip is the recommended installer. Below, we'll cover the most common usage scenarios. For more detail, see the pip docs, which includes a complete Reference Guide.

从 PyPI 安装

Installing from PyPI

最常见的 pip 用法是使用 要求规范符Python 包索引 安装包。一般来说,要求规范符由项目名称和可选的 版本规范符 组成。有关支持的所有规范符的完整描述,请参见 版本规范符规范。以下是一些示例。

安装 "SomeProject" 的最新版本:

python3 -m pip install "SomeProject"
py -m pip install "SomeProject"

安装特定版本:

python3 -m pip install "SomeProject==1.4"
py -m pip install "SomeProject==1.4"

安装一个版本大于或等于某个版本且小于另一个版本:

python3 -m pip install "SomeProject>=1,<2"
py -m pip install "SomeProject>=1,<2"

安装与某个特定版本 兼容 的版本:[4]

python3 -m pip install "SomeProject~=1.4.2"
py -m pip install "SomeProject~=1.4.2"

在这种情况下,意味着安装任何 "==1.4.*" 且版本 ">=1.4.2" 的版本。

The most common usage of pip is to install from the Python Package Index using a requirement specifier. Generally speaking, a requirement specifier is composed of a project name followed by an optional version specifier. A full description of the supported specifiers can be found in the Version specifier specification. Below are some examples.

To install the latest version of "SomeProject":

python3 -m pip install "SomeProject"
py -m pip install "SomeProject"

To install a specific version:

python3 -m pip install "SomeProject==1.4"
py -m pip install "SomeProject==1.4"

To install greater than or equal to one version and less than another:

python3 -m pip install "SomeProject>=1,<2"
py -m pip install "SomeProject>=1,<2"

To install a version that's compatible with a certain version: [4]

python3 -m pip install "SomeProject~=1.4.2"
py -m pip install "SomeProject~=1.4.2"

In this case, this means to install any version "==1.4.*" version that's also ">=1.4.2".

源发行版与 Wheels

Source Distributions vs Wheels

pip 可以从 源代码分发包 (sdist)Wheel 安装软件包,但如果 PyPI 上同时存在两者,pip 会优先选择兼容的 wheel。你可以通过使用例如 --no-binary 选项来覆盖 pip 的默认行为。

Wheel 是一种预构建的 分发包 格式,与 源代码分发包 (sdist) 相比,它提供了更快的安装速度,尤其是当项目包含编译的扩展时。

如果 pip 找不到合适的 wheel 文件来安装,它将会本地构建一个 wheel 并将其缓存,以便将来安装时使用,而不是每次都重新构建源代码分发包。

pip can install from either Source Distributions (sdist) or Wheels, but if both are present on PyPI, pip will prefer a compatible wheel. You can override pip`s default behavior by e.g. using its --no-binary option.

Wheels are a pre-built distribution format that provides faster installation compared to Source Distributions (sdist), especially when a project contains compiled extensions.

If pip does not find a wheel to install, it will locally build a wheel and cache it for future installs, instead of rebuilding the source distribution in the future.

升级软件包

Upgrading packages

将已安装的 SomeProject 升级到 PyPI 上的最新版本。

python3 -m pip install --upgrade SomeProject
py -m pip install --upgrade SomeProject

Upgrade an already installed SomeProject to the latest from PyPI.

python3 -m pip install --upgrade SomeProject
py -m pip install --upgrade SomeProject

安装到用户站点

Installing to the User Site

要安装仅限当前用户的 ,请使用 --user 标志:

python3 -m pip install --user SomeProject
py -m pip install --user SomeProject

有关更多信息,请参阅 pip 文档中的 用户安装 部分。

请注意,在虚拟环境中使用 --user 标志不会产生任何效果——所有安装命令将影响虚拟环境。

如果 SomeProject 定义了任何命令行脚本或控制台入口点,使用 --user 标志会将它们安装到 user base 的二进制目录中,该目录可能已经存在,也可能不存在于你的 shell 的 PATH 中。(从版本 10 开始,pip 会在将脚本安装到 PATH 之外的目录时显示警告。)如果安装后脚本在 shell 中不可用,你需要将该目录添加到你的 PATH :

  • 在 Linux 和 macOS 上,你可以通过运行 python -m site --user-base 来找到用户基础的二进制目录,并在末尾加上 bin。例如,通常会返回 ~/.local (其中 ~ 会展开为你的主目录的绝对路径),因此你需要将 ~/.local/bin 添加到你的 PATH。你可以通过 修改 ~/.profile 来永久设置你的 PATH

  • 在 Windows 上,你可以通过运行 py -m site --user-site 来找到用户基础的二进制目录,然后将 site-packages 替换为 Scripts。例如,这可能返回 C:\Users\Username\AppData\Roaming\Python36\site-packages,因此你需要将 C:\Users\Username\AppData\Roaming\Python36\Scripts 添加到你的 PATH。你可以在 控制面板 中永久设置用户的 PATH。你可能需要注销账户才能使 PATH 更改生效。

To install packages that are isolated to the current user, use the --user flag:

python3 -m pip install --user SomeProject
py -m pip install --user SomeProject

For more information see the User Installs section from the pip docs.

Note that the --user flag has no effect when inside a virtual environment - all installation commands will affect the virtual environment.

If SomeProject defines any command-line scripts or console entry points, --user will cause them to be installed inside the user base's binary directory, which may or may not already be present in your shell's PATH. (Starting in version 10, pip displays a warning when installing any scripts to a directory outside PATH.) If the scripts are not available in your shell after installation, you'll need to add the directory to your PATH:

  • On Linux and macOS you can find the user base binary directory by running

python -m site --user-base and adding bin to the end. For example, this will typically print ~/.local (with ~ expanded to the absolute path to your home directory) so you'll need to add ~/.local/bin to your PATH. You can set your PATH permanently by modifying ~/.profile.

  • On Windows you can find the user base binary directory by running ``py -m

site --user-site`` and replacing site-packages with Scripts. For example, this could return C:\Users\Username\AppData\Roaming\Python36\site-packages so you would need to set your PATH to include C:\Users\Username\AppData\Roaming\Python36\Scripts. You can set your user PATH permanently in the Control Panel. You may need to log out for the PATH changes to take effect.

要求文件

Requirements files

安装在 要求文件 中指定的需求列表。

python3 -m pip install -r requirements.txt
py -m pip install -r requirements.txt

Install a list of requirements specified in a Requirements File.

python3 -m pip install -r requirements.txt
py -m pip install -r requirements.txt

从 VCS 安装

Installing from VCS

从版本控制系统 (VCS) 安装一个项目,并以“可编辑”模式进行安装。有关完整的语法说明,请参阅 pip 的 VCS 支持 部分。

python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git          # 从 git 安装
python3 -m pip install -e SomeProject @ hg+https://hg.repo/some_pkg                # 从 mercurial 安装
python3 -m pip install -e SomeProject @ svn+svn://svn.repo/some_pkg/trunk/         # 从 svn 安装
python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git@feature  # 从某个分支安装
py -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git          # 从 git 安装
py -m pip install -e SomeProject @ hg+https://hg.repo/some_pkg                # 从 mercurial 安装
py -m pip install -e SomeProject @ svn+svn://svn.repo/some_pkg/trunk/         # 从 svn 安装
py -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git@feature  # 从某个分支安装

Install a project from VCS in "editable" mode. For a full breakdown of the syntax, see pip's section on VCS Support.

python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git          # from git
python3 -m pip install -e SomeProject @ hg+https://hg.repo/some_pkg                # from mercurial
python3 -m pip install -e SomeProject @ svn+svn://svn.repo/some_pkg/trunk/         # from svn
python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git@feature  # from a branch
py -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git          # from git
py -m pip install -e SomeProject @ hg+https://hg.repo/some_pkg                # from mercurial
py -m pip install -e SomeProject @ svn+svn://svn.repo/some_pkg/trunk/         # from svn
py -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git@feature  # from a branch

从其他索引安装

Installing from other Indexes

从备用索引安装

python3 -m pip install --index-url http://my.package.repo/simple/ SomeProject
py -m pip install --index-url http://my.package.repo/simple/ SomeProject

在安装过程中,除了 PyPI 之外,还搜索其他索引

python3 -m pip install --extra-index-url http://my.package.repo/simple SomeProject
py -m pip install --extra-index-url http://my.package.repo/simple SomeProject

Install from an alternate index

python3 -m pip install --index-url http://my.package.repo/simple/ SomeProject
py -m pip install --index-url http://my.package.repo/simple/ SomeProject

Search an additional index during install, in addition to PyPI

python3 -m pip install --extra-index-url http://my.package.repo/simple SomeProject
py -m pip install --extra-index-url http://my.package.repo/simple SomeProject

从本地 src 树安装

Installing from a local src tree

以开发模式从本地源安装项目,即使项目看起来已安装,但仍可以从源代码树中进行编辑。

python3 -m pip install -e <path>
py -m pip install -e <path>

你也可以从源代码中正常安装:

python3 -m pip install <path>
py -m pip install <path>

Installing from local src in Development Mode, i.e. in such a way that the project appears to be installed, but yet is still editable from the src tree.

python3 -m pip install -e <path>
py -m pip install -e <path>

You can also install normally from src

python3 -m pip install <path>
py -m pip install <path>

从本地存档安装

Installing from local archives

安装特定的源代码归档文件。

python3 -m pip install ./downloads/SomeProject-1.0.4.tar.gz
py -m pip install ./downloads/SomeProject-1.0.4.tar.gz

从包含归档文件的本地目录安装(并且不检查 PyPI):

python3 -m pip install --no-index --find-links=file:///local/dir/ SomeProject
python3 -m pip install --no-index --find-links=/local/dir/ SomeProject
python3 -m pip install --no-index --find-links=relative/dir/ SomeProject
py -m pip install --no-index --find-links=file:///local/dir/ SomeProject
py -m pip install --no-index --find-links=/local/dir/ SomeProject
py -m pip install --no-index --find-links=relative/dir/ SomeProject

Install a particular source archive file.

python3 -m pip install ./downloads/SomeProject-1.0.4.tar.gz
py -m pip install ./downloads/SomeProject-1.0.4.tar.gz

Install from a local directory containing archives (and don't check PyPI)

python3 -m pip install --no-index --find-links=file:///local/dir/ SomeProject
python3 -m pip install --no-index --find-links=/local/dir/ SomeProject
python3 -m pip install --no-index --find-links=relative/dir/ SomeProject
py -m pip install --no-index --find-links=file:///local/dir/ SomeProject
py -m pip install --no-index --find-links=/local/dir/ SomeProject
py -m pip install --no-index --find-links=relative/dir/ SomeProject

从其他来源安装

Installing from other sources

要从其他数据源(例如 Amazon S3 存储)安装,你可以创建一个辅助应用程序,将数据以符合 simple repository API 格式提供,并使用 --extra-index-url 标志将 pip 指向该索引。

./s3helper --port=7777
python -m pip install --extra-index-url http://localhost:7777 SomeProject

To install from other data sources (for example Amazon S3 storage) you can create a helper application that presents the data in a format compliant with the simple repository API:, and use the --extra-index-url flag to direct pip to use that index.

./s3helper --port=7777
python -m pip install --extra-index-url http://localhost:7777 SomeProject

安装预发布版本

Installing Prereleases

查找预发布和开发版本,除了稳定版本外。默认情况下,pip 只会查找稳定版本。

python3 -m pip install --pre SomeProject
py -m pip install --pre SomeProject

Find pre-release and development versions, in addition to stable versions. By default, pip only finds stable versions.

python3 -m pip install --pre SomeProject
py -m pip install --pre SomeProject

安装“附加内容”

Installing "Extras"

Extras 是软件包的可选“变体(variants)”,可能包含额外的依赖项,从而启用软件包的附加功能。如果你希望安装某个包的额外功能(假设该包提供了额外功能),可以在 pip 安装命令中包括它:

python3 -m pip install 'SomePackage[PDF]'
python3 -m pip install 'SomePackage[PDF]==3.0'
python3 -m pip install -e '.[PDF]'  # 当前目录中的可编辑项目
py -m pip install "SomePackage[PDF]"
py -m pip install "SomePackage[PDF]==3.0"
py -m pip install -e ".[PDF]"  # 当前目录中的可编辑项目

Extras are optional "variants" of a package, which may include additional dependencies, and thereby enable additional functionality from the package. If you wish to install an extra for a package which you know publishes one, you can include it in the pip installation command:

python3 -m pip install 'SomePackage[PDF]'
python3 -m pip install 'SomePackage[PDF]==3.0'
python3 -m pip install -e '.[PDF]'  # editable project in current directory
py -m pip install "SomePackage[PDF]"
py -m pip install "SomePackage[PDF]==3.0"
py -m pip install -e ".[PDF]"  # editable project in current directory