Skip to content

Instantly share code, notes, and snippets.

@TheOnlyWayUp
Created October 8, 2021 11:02
Show Gist options
  • Select an option

  • Save TheOnlyWayUp/02ae18cac095e7900dfbdd8051ee7950 to your computer and use it in GitHub Desktop.

Select an option

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
@TheOnlyWayUp
Copy link
Author

Don't use this, try an environment manager like poetry, pipx, or uv. Plenty more options, and does the above, but much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment