Last active
December 16, 2021 18:16
-
-
Save brianspiering/955beab55f19cf9de20f6791d60b003b to your computer and use it in GitHub Desktop.
Find and update all pip packages within Python
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
# Find and update all pip packages within Python | |
# This code is dangerous but gets the job done 💀 💼 | |
import pkg_resources | |
from subprocess import call | |
ignored = {'pycurl', 'tbb', 'daal', 'gast'} | |
packages = {dist.project_name for dist in pkg_resources.working_set | |
if dist.project_name not in ignored} | |
# Update each package individually | |
for package in packages: | |
call(f"pip install --upgrade {package}", shell=True) | |
# Update every package together | |
# Better handle dependencies but there often errors | |
call("pip install --upgrade " + " ".join(packages), shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment