Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip uninstall package AND unique dependencies

Tags:

python

pip

How does one cleanly uninstall a pip installed package and all dependencies used by package only (i.e. not shared with other packages)?

like image 659
Vishal Avatar asked Jan 01 '23 17:01

Vishal


1 Answers

pip does not natively support removing unused dependencies. This is a related discussion thread by the pip developers.

There are several options you can consider:

  1. There is a package pip-autoremove, but it is no longer maintained, so you cannot be sure if it works and should use it with caution.

  2. There is another package pipdeptree which shows you the dependency tree of installed packages. See the dependency tree yourself and decide what is safe to be deleted.

  3. What I do is to work on virtual environments and write a requirements.txt for each environment. When I want to remove a package, I take it away from requirements.txt, and just completely delete the virtual environment. Then I re-create the environment with pip install -r requirements.txt.

like image 71
Ignatius Avatar answered Jan 12 '23 14:01

Ignatius