The Python Oracle

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

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Flying Over Ancient Lands

--

Chapters
00:00 Does Uninstalling A Package With &Quot;Pip&Quot; Also Remove The Dependent Packages?
00:19 Answer 1 Score 411
00:34 Accepted Answer Score 159
01:08 Answer 3 Score 18
01:24 Answer 4 Score 5
01:55 Answer 5 Score 1
02:05 Thank you

--

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

--

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.