Question: 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: 
I wanted to elevate this answer out of a comment section because it's one of the most elegant solutions in the thread. Full credit for this answer goes to [@joeb](https://stackoverflow.com/users/174652/joeb).

```
pip uninstall -y -r <(pip freeze)

```

This worked great for me for the use case of clearing my user packages folder outside the context of a virtualenv which many of the above answers don't handle.

*Edit: Anyone know how to make this command work in a Makefile?*

Bonus: A bash alias
-------------------

I add this to my bash profile for convenience:

```
alias pipuninstallall="pip uninstall -y -r <(pip freeze)"

```

Then run:

```
pipuninstallall

```

Alternative for Pipenv
----------------------

If you are using [pipenv](https://github.com/pypa/pipenv), you can run:

```
pipenv uninstall --all

```

Alternative for Poetry
----------------------

If you are using [Poetry](https://github.com/python-poetry/poetry), run:

```
poetry env remove --python3.9

```

(Note that you need to change the version number there to match whatever your Python version is.)
The quickest way is to remake the virtualenv completely. I'm assuming you have a requirements.txt file that matches production, if not:

```
# On production:
pip freeze > reqs.txt

# On your machine:
rm $VIRTUALENV_DIRECTORY
mkdir $VIRTUALENV_DIRECTORY
pip install -r reqs.txt

```