How does one cleanly uninstall a pip installed package and all dependencies used by package only (i.e. not shared with other packages)?
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:
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.
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.
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
.