DEV Community

Bruce Axtens
Bruce Axtens

Posted on

Updating everything PyPI in Windows

I have a number of collections of software: npm-based, scoop-based, pip-based, and cygwin64-based. I also use FileHippo App Manager to update applications and have used Ninite from time to time.

I was trying to find a way of updating my PyPI collection. Below are three adapted-for-Windows approaches based on similar offerings for Linux:

  • Using pip, sed and xargs (available through scoop)
pip freeze | sed -e "s/==.*//" | xargs pip install -U
Enter fullscreen mode Exit fullscreen mode

Here we pipe pip freeze through sed replacing double-equals and everything after with an empty string, then pipe that into xargs which runs pip.

  • Using pip and sed with a more CMD-like approach
FOR /F %f IN ('pip freeze ^| sed -e "s/==.*//"') DO pip install -U %f
Enter fullscreen mode Exit fullscreen mode

In this approach we use the file-set parameter (/F) on the for. The command between the single-quotes is evaluated (which does the pip and sed thing of #1) and every line is then placed into the %f meta-variable for execution in the do clause.

  • Using pip and CMD only.
FOR /F "tokens=1 delims==" %f IN ('pip freeze') DO pip install -U %f
Enter fullscreen mode Exit fullscreen mode

Finally, we use the for /f method but this time give extra parameters to control the parsing of the output from pip freeze: we split on = and take the first token. Each result goes into %f for processing by the do clause.

There are other ways of doing this on Windows, like PowerShell. Hopefully, someone will demonstrate how.

Top comments (0)