Skip to content

Instantly share code, notes, and snippets.

@HunterKohler
Last active December 24, 2021 21:53
Show Gist options
  • Save HunterKohler/dc8a719ae6ed3db52aacd4fe3f607fff to your computer and use it in GitHub Desktop.
Save HunterKohler/dc8a719ae6ed3db52aacd4fe3f607fff to your computer and use it in GitHub Desktop.
Update all global pip dependencies with a simple script
#!/usr/bin/env python3
import pathlib
import subprocess
import tempfile
def main():
result = subprocess.run(
["pip3", "freeze"], text=True, capture_output=True, check=True)
reqs = result.stdout.replace("==", ">=")
with tempfile.TemporaryDirectory() as dirpath:
reqs_txt = pathlib.Path(dirpath, "requirements.txt")
reqs_txt.write_text(reqs)
subprocess.run(
["pip3", "install", "-r", "requirements.txt", "--upgrade"],
check=True)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment