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

PythonPackagesPip

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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.

Solution 3 - Python

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

Solution 4 - Python

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 ...

Solution 5 - Python

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHosseinView Question on Stackoverflow
Solution 1 - Pythonbwv549View Answer on Stackoverflow
Solution 2 - PythonBengineerView Answer on Stackoverflow
Solution 3 - PythonlinibouView Answer on Stackoverflow
Solution 4 - Pythondavid davidView Answer on Stackoverflow
Solution 5 - Pythoncls1991View Answer on Stackoverflow