如何在 Ubuntu 22.04 LTS 上安装 Python Pip

在本教程中,我们将向您展示如何在 Ubuntu 22.04 LTS 上安装 Python Pip。 对于那些不知道的人,Pip 是标准的包管理系统,用于安装和管理用 Python 编写的包的软件。 使用 PIP,您可以从 Python 包索引 (PyPI) 列出、搜索和下载以安装包。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 Ubuntu 22.04 (Jammy Jellyfish) 上逐步安装 Python Pip。 对于 Ubuntu 22.04 和任何其他基于 Debian 的发行版,如 Linux Mint、Elementary OS、Pop!_OS 等,您可以按照相同的说明进行操作。

先决条件

  • 运行以下操作系统之一的服务器:Ubuntu 22.04、20.04 和任何其他基于 Debian 的发行版,如 Linux Mint。
  • 建议您使用全新的操作系统安装来防止任何潜在问题。
  • 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
  • 一个 non-root sudo user或访问 root user. 我们建议充当 non-root sudo user,但是,如果您在充当 root 时不小心,可能会损害您的系统。

在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 Python Pip

步骤 1. 首先,通过运行以下命令确保所有系统包都是最新的 apt 终端中的命令。

sudo apt update sudo apt upgrade sudo apt install gnupg ca-certificates apt-transport-https software-properties-common

步骤 2. 在 Ubuntu 22.04 上安装 Python Pip。

默认情况下,Python 在 Ubuntu 22.04 基础存储库中可用。 现在运行以下命令将最新版本的 Python Pip 安装到您的 Ubuntu 系统:

sudo apt install python3-pip

完成安装过程后,运行以下命令通过检查 pip 版本来验证安装:

pip3 --version

步骤 3. Pip 命令示例。

要查看所有 pip 命令和选项的列表,请键入以下命令:

[[email protected] ~]# pip --help  Usage:      pip <command></command> [options]  Commands:   install                     Install packages.   uninstall                   Uninstall packages.   freeze                      Output installed packages in requirements format.   list                        List installed packages.   show                        Show information about installed packages.   search                      Search PyPI for packages.   wheel                       Build wheels from your requirements.   zip                         DEPRECATED. Zip individual packages.   unzip                       DEPRECATED. Unzip individual packages.   bundle                      DEPRECATED. Create pybundles.   help                        Show help for commands.  General Options:   -h, --help                  Show help.   -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.   -V, --version               Show version and exit.   -q, --quiet                 Give less output.   --log-file            Path to a verbose non-appending log, that only logs failures. This                               log is active by default at /home/sharad/.pip/pip.log.   --log                 Path to a verbose appending log. This log is inactive by default.   --proxy              Specify a proxy in the form [user:[email protected]]proxy.server:port.   --timeout              Set the socket timeout (default 15 seconds).   --exists-action     Default action when a path already exists: (s)witch, (i)gnore,                               (w)ipe, (b)ackup.   --cert                Path to alternate CA bundle.

要安装新的 python 包类型:

pip3 install <pack_name>

例如,要通过 Pip 安装 numpy,您将运行以下命令:

python3 -m pip install numpy

要卸载 pip 类型安装的 python 包:

pip3 uninstall <pack_name>

要搜索 python 包类型:

pip3 search <pack_name>

恭喜! 您已成功安装 Python Pip。 感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装 Python Pip。 如需更多帮助或有用信息,我们建议您查看 Python 官方网站.