I have a pip requirements file that changes during development.
Can pip be made to uninstall packages that do not appear in the requirement
pip
Piggybacking off @stephen-j-fuhry here is a powershell equivalent I use:
pip freeze | ? { $_ -notmatch ((gc req.txt) -join "|") }