使用 Linux 包管理器安装 pip/setuptools/wheel

Installing pip/setuptools/wheel with Linux Package Managers

Page Status:

Incomplete

Last Reviewed:

2021-07-26

本节介绍如何使用 Linux 包管理器安装 pipSetuptoolswheel

如果您使用的是从 python.org 下载的 Python,那么本节内容不适用。请参阅 安装软件包的要求 部分。

请注意,特定 Linux 发行版所支持的 pipSetuptoolswheel 版本通常会在发布时已经过时,更新通常仅会出于安全原因进行,而不会进行功能更新。对于某些发行版,可以启用额外的仓库来提供更新版本。我们所知道的这些仓库将在下文中解释。

还需注意,某些发行版通常会为了安全性和标准化应用补丁。这可能会导致与原始未打补丁版本不同的错误或意外行为。如果已知存在这种情况,我们会在下文中说明。

This section covers how to install pip, Setuptools, and wheel using Linux package managers.

If you're using a Python that was downloaded from python.org, then this section does not apply. See the 安装软件包的要求 section instead.

Note that it's common for the versions of pip, Setuptools, and wheel supported by a specific Linux Distribution to be outdated by the time it's released to the public, and updates generally only occur for security reasons, not for feature updates. For certain Distributions, there are additional repositories that can be enabled to provide newer versions. The repositories we know about are explained below.

Also note that it's somewhat common for Distributions to apply patches for the sake of security and normalization to their own standards. In some cases, this can lead to bugs or unexpected behaviors that vary from the original unpatched versions. When this is known, we will make note of it below.

Fedora

command:

sudo dnf install python3-pip python3-wheel

要了解有关 Fedora 中 Python 的更多信息,请访问 官方 Fedora 文档Python 课堂Fedora Loves Python

command:

sudo dnf install python3-pip python3-wheel

To learn more about Python in Fedora, please visit the official Fedora docs, Python Classroom or Fedora Loves Python.

CentOS/RHEL

CentOS 和 RHEL 在其核心仓库中不提供 pipwheel,虽然 Setuptools 是默认安装的。

要为系统 Python 安装 pip 和 wheel,有两种选择:

  1. 使用 EPEL 仓库 ,按照 这些说明 启用它。在 EPEL 7 上,您可以通过以下方式安装 pip 和 wheel:

sudo dnf install python3-pip python3-wheel

由于 EPEL 仅提供额外的不冲突包,因此 EPEL 不提供 setuptools,因为它已经包含在核心仓库中。

  1. 使用 PyPA Copr Repo,按照 这些说明 [1] 启用它。然后,您可以通过以下方式安装 pip 和 wheel:

sudo dnf install python3-pip python3-wheel

要额外升级 setuptools,可以运行:

sudo dnf upgrade python3-setuptools

要在一个并行的非系统环境中安装 pip、wheel 和 setuptools(使用 yum),有两种选择:

  1. 使用 "软件集合"(Software Collections)功能启用一个包含 pip、setuptools 和 wheel 的并行集合。

    请注意,集合中可能不包含最新版本。

  2. 启用 IUS 仓库,并安装一个 可并行安装的 Python 版本,同时安装 pip、setuptools 和 wheel,这些版本通常保持较新。

    例如,在 CentOS7/RHEL7 上安装 Python 3.4:

    sudo yum install python34u python34u-wheel
    

CentOS and RHEL don't offer pip or wheel in their core repositories, although Setuptools is installed by default.

To install pip and wheel for the system Python, there are two options:

  1. Enable the EPEL repository using

these instructions. On EPEL 7, you can install pip and wheel like so:

sudo dnf install python3-pip python3-wheel

Since EPEL only offers extra, non-conflicting packages, EPEL does not offer setuptools, since it's in the core repository.

  1. Enable the `PyPA Copr Repo

<https://copr.fedorainfracloud.org/coprs/pypa/pypa/>`_ using these instructions [1]. You can install pip and wheel like so:

sudo dnf install python3-pip python3-wheel

To additionally upgrade setuptools, run:

sudo dnf upgrade python3-setuptools

To install pip, wheel, and setuptools, in a parallel, non-system environment (using yum) then there are two options:

  1. Use the "Software Collections" feature to enable a parallel collection that

includes pip, setuptools, and wheel.

Be aware that collections may not contain the most recent versions.

  1. Enable the IUS repository and

install one of the parallel-installable Pythons, along with pip, setuptools, and wheel, which are kept fairly up to date.

For example, for Python 3.4 on CentOS7/RHEL7:

sudo yum install python34u python34u-wheel

openSUSE

sudo zypper install python3-pip python3-setuptools python3-wheel

Debian/Ubuntu and derivatives

首先,通过运行以下命令来更新和刷新仓库列表:

sudo apt update
sudo apt install python3-venv python3-pip

警告

最近的 Debian/Ubuntu 版本已修改 pip,默认使用 "User Scheme",这是一个重要的行为变化,可能会让一些用户感到惊讶。

Firstly, update and refresh repository lists by running this command:

sudo apt update
sudo apt install python3-venv python3-pip

警告

Recent Debian/Ubuntu versions have modified pip to use the "User Scheme" by default, which is a significant behavior change that can be surprising to some users.

Arch Linux

sudo pacman -S python-pip