Skip to content

Instantly share code, notes, and snippets.

@brianspiering
Last active December 16, 2021 18:16
Show Gist options
  • Save brianspiering/955beab55f19cf9de20f6791d60b003b to your computer and use it in GitHub Desktop.
Save brianspiering/955beab55f19cf9de20f6791d60b003b to your computer and use it in GitHub Desktop.
Find and update all pip packages within Python
# 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