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

页面状态

不完全的

最后审查

2021-07-26

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

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

  2. Enable the PyPA Copr Repo 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.

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

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

1

Currently, there is no “copr” yum plugin available for CentOS/RHEL, so the only option is to manually place the repo files as described.