Created
February 2, 2024 20:53
-
-
Save allen-munsch/c785489dd57ebf9e4f6af45095ac8daa to your computer and use it in GitHub Desktop.
list all installed packages using importlib 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
import importlib.metadata | |
def list_installed_packages(): | |
distributions = importlib.metadata.distributions() | |
installed_packages = [] | |
for dist in distributions: | |
args = (dist.metadata['Name'], dist.version) | |
installed_packages.append(args) | |
installed_packages.sort() # Sort the packages by name | |
for package_name, version in installed_packages: | |
print(f"{package_name}=={version}") | |
if __name__ == "__main__": | |
list_installed_packages() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment