Skip to content

Instantly share code, notes, and snippets.

@TheOnlyWayUp
Created October 8, 2021 11:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheOnlyWayUp/02ae18cac095e7900dfbdd8051ee7950 to your computer and use it in GitHub Desktop.
Save TheOnlyWayUp/02ae18cac095e7900dfbdd8051ee7950 to your computer and use it in GitHub Desktop.
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
#Uses list comprehension to create a list of all packages installed, and then get their names.
call("pip install --upgrade " + ' '.join(packages), shell=True)
#Call is like os.system, it runs pip install upgrade and the join essentially seperates all the packages with a " ", ex if you had the packages discord and setuptools installed, the list would become ["discord", "setuptools"] and it would run pip install -upgrade discord setuptools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment