如何在Ubuntu上安装PIP

PIP是一种用于安装和管理在Python中编写的软件包的包安装程序。
用户可以使用PIP从Python包索引和其他索引安装包。

第3步:使用pip安装包

显示有用的命令选项以及如何使用它们:

pip3 --help
pip install --help

输出示例:

Usage:   
  pip  [options]
Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.
General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -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. Option is additive, and can be used up to 3 times (corresponding
                              to WARNING, ERROR, and CRITICAL logging levels).
  --log                 Path to a verbose appending log.

使用Python项目时,创建虚拟环境始终是一个好主意。
通常,PIP包安装程序用于Python虚拟环境中,其中每个环境被隔离针对特定项目。

示例:

创建一个名为Python 3的虚拟环境 confidential

首先运行以下命令,首先安装Python虚拟环境模块:

sudo apt install python3-venv

然后创建一个名为的新环境 confidential

python3 -m venv ~/confidential

只需运行以下命令即可激活环境:

source ~/confidential/bin/activate

在此特定环境中,我们可以通过PIP开始安装包

例如,安装一个名为Python软件包 python-openstackclient

pip3 install python-openstackclient

通过PIP升级软件包:

pip3 install --upgrade python-openstackclient

通过PIP卸载包 :

pip3 uninstall python-openstackclient

当我们完成Python项目时,只需运行 deactivate命令返回正常shell。

deactivate

第2步:安装PIP与Python 2一起使用

运行以下命令以安装它。

sudo apt update
sudo apt install python-pip

查看已安装的pip的版本

pip --version

输出示例

pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

第1步:安装PIP与Python 3一起使用

安装PIP的命令与Python版本3一起使用。

sudo apt update
sudo apt install python3-pip

验证是否安装了PIP:

pip3 --version

输出示例

pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
日期:2020-07-07 20:55:27 来源:oir作者:oir