Skip to content

Instantly share code, notes, and snippets.

@lboulard
Last active February 2, 2020 10:47
Show Gist options
  • Save lboulard/9adba1916ed1af83abe176e335d0ae5b to your computer and use it in GitHub Desktop.
Save lboulard/9adba1916ed1af83abe176e335d0ae5b to your computer and use it in GitHub Desktop.
Manage python packages on windows

Upgrade all

Upgrade pip before in case of very old version on system:

py -3 -m pip install --user -U pip

Upgrade all root packages in one go (avoid generating broken dependencies between root projects):

DEL "%TMP%\pip-upgrade.txt"
FOR /F "delims==" %i IN ('py -3 -m pip list --user --not-required --format=freeze') DO @ECHO %i >>"%TMP%\pip-upgrade.txt"
TYPE "%TMP%\pip-upgrade.txt"
py -3 -m pip install --user -U --upgrade-strategy=eager -r "%TMP%\pip-upgrade.txt"
py -3 -m pip check

Move installation from a version to another

For example moving from Python 3.7 to Python 3.8:

DEL "%TMP%\pip-upgrade.txt"
FOR /F "delims==" %i IN ('py -3.7 -m pip list --user --not-required --format=freeze') DO @ECHO %i >>"%TMP%\pip-upgrade.txt"
TYPE "%TMP%\pip-upgrade.txt"
py -3.8 -m pip install --user -U --upgrade-strategy=eager -r "%TMP%\pip-upgrade.txt"
py -3.8 -m pip check

Remove all

Remove all user installed packages:

py -3.6 -m pip list --user --format=freeze | FINDSTR /R /V "^pip= ^setuptools= ^virtualenv= ^wheel= ^pipenv=" >"%TMP%\pip-removal.txt"
TYPE "%TMP%\pip-removal.txt"
py -3.6 -m pip uninstall -y -r "%TMP%\pip-removal.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment