What is the easiest way to remove all packages installed by pip?

blueberryfields picture blueberryfields · Jun 28, 2012 · Viewed 528.4k times · Source

I'm trying to fix up one of my virtualenvs - I'd like to reset all of the installed libraries back to the ones that match production.

Is there a quick and easy way to do this with pip?

Answer

blueberryfields picture blueberryfields · Jun 28, 2012

I've found this snippet as an alternative solution. It's a more graceful removal of libraries than remaking the virtualenv:

pip freeze | xargs pip uninstall -y

In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below):

pip freeze | grep -v "^-e" | xargs pip uninstall -y