如何使用Pip安装特定版本的Python软件包?

您所在的位置:网站首页 英语对话日常三人 如何使用Pip安装特定版本的Python软件包?

如何使用Pip安装特定版本的Python软件包?

2024-02-16 17:27| 来源: 网络整理| 查看: 265

Pip is the most popular tool and the command used to install 3rd party packages into Python. pip can be used for both PYython2 and Python3. In this tutorial, we will learn how to install a specific version of a Python package with the pip command.

Pip是最受欢迎的工具,也是用于将第3方软件包安装到Python中的命令。 pip可用于PYython2和Python3。 在本教程中,我们将学习如何使用pip命令安装特定版本的Python软件包。

搜索包 (Search Package)

Before installing a specific version of the Python package we can search the package for its complete name and version information. We will use search command in this example.

在安装特定版本的Python软件包之前,我们可以在该软件包中搜索其完整名称和版本信息。 在此示例中,我们将使用search命令。

$ pip search django Search Package Search Package 搜索包 显示包装信息和版本(Show Package Information and Version)

We can show the Python package information like name, version, etc. The inversion information is important because we will install a specific version or downgrade the Python package.

我们可以显示Python软件包信息,例如名称,版本等。反转信息非常重要,因为我们将安装特定版本或降级Python软件包。

$ pip show django Show Package Information and Version Show Package Information and Version 显示包装信息和版本 使用pip命令安装特定的软件包版本(Install Specific Package Version with pip Command)

We will install a specific version of the Django Python package with pip. We will specify the version we want to install with the equal sign. In this example, we will install the Django version 2.2.1 which is not recent. We will use a double equation sign to specify the version. We will also use the --user option in order to prevent other system users package downgrade. This will only affect the current user.

我们将使用pip安装特定版本的Django Python软件包。 我们将用等号指定要安装的版本。 在此示例中,我们将安装最新的Django 2.2.1版本。 我们将使用双方程符号来指定版本。 我们还将使用--user选项,以防止其他系统用户软件包降级。 这只会影响当前用户。

$ pip3 install --user django==2.2.1 Install Specific Package Version with pip Command Install Specific Package Version with pip Command 使用pip命令安装特定的软件包版本

From the screenshot, we see that the currently installed recent Django version is uninstalled automatically.

从屏幕截图中,我们看到当前安装的最新Django版本已自动卸载。

使用pip命令安装指定范围内的软件包版本 (Install Package Version Which Is In Specified Range with pip Command)

In the previous example, we have installed a specific django version. But we can also specify the version range with the ;= or ;=. This will select the latest version which complies with the given expression and install it.

在前面的示例中,我们安装了特定的Django版本。 但是我们也可以使用;=或;=来指定版本范围。 这将选择符合给定表达式的最新版本并安装它。

$ pip install django < 2 Install Package Version Which Is In Specified Range with pip Command Install Package Version Which Is In Specified Range with pip Command 使用pip命令安装指定范围内的软件包版本 使用pip命令强制安装特定软件包版本(Force Installation of  Specific Package Version with pip Command)

If there are some minor problems related to the installation, dependency, etc. We can force the installation with the --force-reinstall option.

如果存在与安装,依赖项等有关的一些小问题。我们可以使用--force-reinstall选项强制安装。

$ pip3 install --force-reinstall --user django==2.2.1 使用pip命令删除特定的软件包版本 (Remove Specific Package Version with pip Command)

We can also remove the specific package version with the pip command. There is a different alternative. As only a single version can be installed at the same time different version installation will uninstall currently installed version.

我们还可以使用pip命令删除特定的软件包版本。 有另一种选择。 由于只能同时安装一个版本,因此不同版本的安装将卸载当前安装的版本。

$ pip uninstall django $ pip2 uninstall django $ pip2 uninstall django Remove Specific Package Version with pip Command Remove Specific Package Version with pip Command 使用pip命令删除特定的软件包版本 LEARN MORE  How To Update/Upgrade A Python Package with Pip? 了解更多如何使用Pip更新/升级Python软件包?

翻译自: https://www.poftut.com/how-to-install-specific-version-of-python-package-with-pip/



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3