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
If you have packages installed directly from github/gitlab, those will have @
.
Like:
django @ git+https://github.com/django.git@<sha>
You can add cut -d "@" -f1
to get just the package name that is required to uninstall it.
pip freeze | cut -d "@" -f1 | xargs pip uninstall -y