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?
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?
Other answers that use
pip list
orpip freeze
must include--local
else it will also uninstall packages that are found in the common namespaces.So here are the snippets I regularly use
or
Learn more about this behavior by issuing
pip freeze --help
This will work for all Mac, Windows and Linux System. To get the list of all pip package in the requirements.txt file (Note: This will overwrite requirements.txt if exist else will create the new one.)
Now to remove one by one
If we want to remove all at once then
If you're working on an existing project that has a
requirements.txt
file and your environment has diverged, simply replacerequirements.txt
from the above examples withtoberemoved.txt
. Then, once you have gone through the steps above, you can use therequirements.txt
to update your now clean environment.And For single command without creating any file (As joeb suggested).
Its an old question I know but I did stumble across it so for future reference you can now do this:
from the pip documentation version 8.1
I've found this snippet as an alternative solution. It's a more graceful removal of libraries than remaking the virtualenv:
In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below):
If you're running
virtualenv
:for example, if your virtualenv is
/Users/you/.virtualenvs/projectx
, then you'd run:if you don't know where your virtual env is located, you can run
which python
from within an activated virtual env to get the pathPip has no way of knowing what packages were installed by it and what packages were installed by your system's package manager. For this you would need to do something like this
for rpm-based distros (replace python2.7 with your python version you installed pip with):
for a deb-based distribution:
then to clean up empty directories left over:
I found the top answer very misleading since it will remove all (most?) python packages from your distribution and probably leave you with a broken system.