The Python Oracle

Does uninstalling a package with "pip" also remove the dependent packages?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Unforgiving Himalayas Looping

--

Chapters
00:00 Question
00:26 Accepted answer (Score 147)
01:10 Answer 2 (Score 369)
01:28 Answer 3 (Score 10)
01:48 Answer 4 (Score 3)
02:30 Thank you

--

Full question
https://stackoverflow.com/questions/7915...

Accepted answer links:
[pip-autoremove]: https://github.com/invl/pip-autoremove

Answer 2 links:
[pip-autoremove]: https://github.com/invl/pip-autoremove

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #package #pip

#avk47



ANSWER 1

Score 419


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

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



ACCEPTED ANSWER

Score 162


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.




ANSWER 3

Score 18


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




ANSWER 4

Score 1


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