Skip to content

Instantly share code, notes, and snippets.

@Diapolo10
Last active December 18, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diapolo10/cc0eb3a15bee5099a206b9caa361bf2c to your computer and use it in GitHub Desktop.
Save Diapolo10/cc0eb3a15bee5099a206b9caa361bf2c to your computer and use it in GitHub Desktop.
@echo off
rem Define a (local) name for the temporary file
setlocal
set temp="tmp.txt"
rem Copy the list of outdated modules to a text file
call pip list --outdated > %temp%
rem Process the text file to only contain module names
call python -c "m='\n'.join(map(lambda x: x.split()[0], open('%temp%', 'r').readlines())); open('%temp%', 'w').write(m)"
rem Pipe the file back to pip and install the modules
call pip install --upgrade -r %temp%
rem Delete the text file
del %temp%
rem Free the now-unnecessary variable for the filename
endlocal
@Diapolo10
Copy link
Author

This gist basically uses pip's ability to list whatever libraries are out-of-date, saves this to a file, modifies the file to only contain the module names, uses this new file to install the up-to-date versions and then finally removes the temporary file.

Even if the file wouldn't be deleted, the script doesn't break. That being said, it will only work as long as pip's output syntax doesn't change drastically.

Also, never use Python one-liners like this one. My script is just an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment