问题:使用“ pip”卸载软件包还会删除相关软件包吗?

当您pip用来安装软件包时,所有必需的软件包也会随之安装(依赖关系)。卸载该软件包还会删除从属软件包吗?

When you use pip to install a package, all the required packages will also be installed with it (dependencies). Does uninstalling that package also remove the dependent packages?


回答 0

不,它不会卸载依赖包。它仅删除指定的软件包:

$ pip install specloud
$ pip freeze # all the packages here are dependencies of specloud package

figleaf == 0.6.1
鼻子== 1.1.2
pinocchio == 0.3
specloud == 0.4.5

$ pip uninstall specloud
$ pip freeze

figleaf == 0.6.1
鼻子== 1.1.2
匹诺曹== 0.3

如您所见,这些程序包是来自的依赖项specloud,它们仍然存在,但不是specloud程序包本身。

如下所述,您可以安装并使用pip-autoremove实用程序删除软件包以及未使用的依赖项。

No, it doesn’t uninstall the dependencies packages. It only removes the specified package:

$ pip install specloud
$ pip freeze # all the packages here are dependencies of specloud package

figleaf==0.6.1
nose==1.1.2
pinocchio==0.3
specloud==0.4.5

$ pip uninstall specloud
$ pip freeze

figleaf==0.6.1
nose==1.1.2
pinocchio==0.3

As you can see those packages are dependencies from specloud and they’re still there, but not the specloud package itself.

As mentioned below, You can install and use the pip-autoremove utility to remove a package plus unused dependencies.


回答 1

您可以安装并使用pip-autoremove实用程序删除软件包以及未使用的依赖项。

# install pip-autoremove
pip install pip-autoremove
# remove "somepackage" plus its dependencies:
pip-autoremove somepackage -y

You can install and use the pip-autoremove utility to remove a package plus unused dependencies.

# install pip-autoremove
pip install pip-autoremove
# remove "somepackage" plus its dependencies:
pip-autoremove somepackage -y

回答 2

我已经使用以下bash行成功删除了软件包的依赖项:

for dep in $(pip show somepackage | grep Requires | sed 's/Requires: //g; s/,//g') ; do pip uninstall -y $dep ; done

这在pip 1.5.4上有效

i’ve successfully removed dependencies of a package using this bash line:

for dep in $(pip show somepackage | grep Requires | sed 's/Requires: //g; s/,//g') ; do pip uninstall -y $dep ; done

this worked on pip 1.5.4


回答 3

我发现了解决方案,尽管对于某些人来说可能有点困难。

第一步(适用于python3和linux):
pip3 install pip-autoremove
第二步:
cd /home/usernamegoeshere/.local/bin/
第三步:
gedit /home/usernamegoeshere/.local/lib/python3.8/site-packages/ pip_autoremove.py
并将所有pip更改为pip3第四步:./ pip-autoremove packagenamegoeshere

至少,这是对我有用的…

I have found the solution even though it might be a little difficult for some to carry out.

1st step (for python3 and linux):
pip3 install pip-autoremove
2nd step:
cd /home/usernamegoeshere/.local/bin/
3rd step:
gedit /home/usernamegoeshere/.local/lib/python3.8/site-packages/pip_autoremove.py
and change all pip(s) to pip3 4th step: ./pip-autoremove packagenamegoeshere

At least, this was what worked for me …


回答 4

您可以尝试使用https://github.com/cls1991/pef。它将删除软件包及其所有依赖项。

You may have a try for https://github.com/cls1991/pef. It will remove package with its all dependencies.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。