Does uninstalling a package with “pip” also remove

2019-01-10 12:25发布

问题:

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?

回答1:

No, it doesn't uninstall the dependencies packages:

$ pip install specloud
$ pip freeze

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 all the packages are still there but not the specloud package itself.



回答2:

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


回答3:

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



回答4:

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