Last active
December 24, 2021 21:53
-
-
Save HunterKohler/dc8a719ae6ed3db52aacd4fe3f607fff to your computer and use it in GitHub Desktop.
Update all global pip dependencies with a simple script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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