Python Pip command provides search, install, update, uninstall packages. We can use pip command to uninstall packages easily even there are some alternatives like easy_install.
Python Pip命令提供搜索,安装,更新,卸载软件包。 即使有easy_install之类的替代方法,我们也可以使用pip命令轻松卸载软件包。
用Pip列出已经安装的Python软件包 (List Already Installed Python Packages with Pip)
Before uninstalling or removing Python packages with pip we will list already installed Python packages. We will use list
command for pip like below.
在通过pip卸载或删除Python软件包之前,我们将列出已安装的Python软件包。 我们将如下所示对pip使用list
命令。
$ pip list
![List Already Installed Python Packages with Pip](https://i-blog.csdnimg.cn/blog_migrate/b3f2bbcd4b5cb6d32b1a43daa1e3b788.png)
We can see that the following information is provided by listing installed packages.
通过列出已安装的软件包,我们可以看到以下信息。
- `Package` column shows the package complete name “包裹”列显示包裹的完整名称
- `Version` column shows the most recent version of the given package“版本”列显示了给定软件包的最新版本
列出/显示Python软件包信息,版本(List/Display Python Packages Information, Version)
We can also show a given package complete information with the show
command which can be useful before uninstalling it. In this example, we will show information about the Python package named Django.
我们还可以使用show
命令显示给定的软件包完整信息,这在卸载之前可能很有用。 在此示例中,我们将显示有关名为Django的Python软件包的信息。
$ pip show django
![List/Display Python Packages Information, Version](https://i-blog.csdnimg.cn/blog_migrate/4b061254bb5a73dfae3c149beebff9a5.png)
使用Pip,Pip2,Pip3卸载/删除Python软件包(Uninstall/Remove Python Package with Pip, Pip2, Pip3)
We can uninstall the package with the uninstall
pip command. We will also provide the package name. In this example, we will uninstall the package named django
.
我们可以使用uninstall
pip命令来卸载软件包。 我们还将提供包裹名称。 在此示例中,我们将卸载名为django
的软件包。
$ pip uninstall django
![Uninstall/Remove Python Package with Pip](https://i-blog.csdnimg.cn/blog_migrate/d145a1ad5e2f5240074175d9ece81eaf.png)
We can see that the directories and files removed are listed and a confirmation is shown where we will input y
in order to accept the removal. After the remove/uninstall completed we will be shown Successfully uninstalled Django-2.2.5
我们可以看到列出了删除的目录和文件,并显示了一个确认,我们将在其中输入y
以接受删除。 删除/卸载完成后,我们将显示Successfully uninstalled Django-2.2.5
If we want to remove packages related to the Python2 we can use the same command for the pip2
command like below.
如果我们想删除与Python2相关的软件包,我们可以对pip2
命令使用相同的命令,如下所示。
$ pip2 uninstall django
If we want to remove packages related to the Python3 we can use the same command for the pip3
command like below.
如果我们想删除与Python3相关的软件包,我们可以对pip3
命令使用相同的命令,如下所示。
$ pip3 uninstall django
使用Pip卸载/删除具有要求的Python软件包 (Uninstall/Remove Python Package with Requirements with Pip)
Modern Python applications and projects provide the required files in order to list the package list which should be installed. We can use this requirement file in order to specify the packages we have to remove the requirement file. In this example, the requirement file contains the following content with the name of requirements.txt
.
现代Python应用程序和项目提供了必需的文件,以便列出应安装的软件包列表。 我们可以使用此需求文件来指定必须删除需求文件的软件包。 在此示例中,需求文件包含以下内容,其名称为requirements.txt
。
django
pycups
PyGObject
PyJWT
pymacaroons
PyNaCl
pyRFC3339
AND we will remove this requirements.txt file content like below.
并且我们将删除此requirements.txt文件内容,如下所示。
$ pip uninstall requirements.txt
无需询问Pip即可卸载/删除Python软件包 (Uninstall/Remove Python Package Without Asking Confirmation with Pip)
By default the package uninstallation or removal requires a confirmation from the user. This is generally providing the y
which is a short form of Yes
to accept package uninstall. We can automatically accept the confirmation and skip it with the -y
or --yes
option like below.
默认情况下,软件包的卸载或删除需要用户的确认。 通常,这是提供y
形式, Yes
接受软件包卸载的缩写。 我们可以自动接受确认,并使用-y
或--yes
选项跳过它,如下所示。
$ pip uninstall -y django
$ pip2 uninstall -y django
$ pip3 uninstall -y django
使用Pip卸载/删除特定用户的Python软件包 (Uninstall/Remove Python Package For Specific User with Pip)
pip Python packages may be installed for a specific user into the users home directory. So we can uninstall given python package for a specific user with the --user
option by providing the user name. In this example, we will remove packages for the current user.
pip Python软件包可以为特定用户安装到用户的主目录中。 因此,我们可以使用--user
选项通过提供用户名来卸载特定用户的给定python软件包。 在此示例中,我们将删除当前用户的软件包。
$ pip uninstall --user django
$ pip2 uninstall --user django
$ pip3 uninstall --user django
使用easy_install卸载/删除Python软件包 (Uninstall/Remove Python Package with easy_install)
We can also use the easy_install
command in order to remove installed python packages. We will use -m
option and provide the package name. In this example, we will remove the package named django with the easy_install command.
我们还可以使用easy_install
命令来删除已安装的python软件包。 我们将使用-m
选项并提供软件包名称。 在此示例中,我们将使用easy_install命令删除名为django的软件包。
$ easy_install -m django
翻译自: https://www.poftut.com/how-to-uninstall-a-package-with-pip/