Skip to content

Instantly share code, notes, and snippets.

@RhetTbull
Created October 14, 2025 14:55
Show Gist options
  • Select an option

  • Save RhetTbull/bf8d4243f0041576215d1c7224895af4 to your computer and use it in GitHub Desktop.

Select an option

Save RhetTbull/bf8d4243f0041576215d1c7224895af4 to your computer and use it in GitHub Desktop.
Get the path to an installed python package and the version number.
#!/usr/bin/env python3
"""Get info about a Python package including install path and version"""
import argparse
import importlib.metadata as metadata
def main():
parser = argparse.ArgumentParser(description='Get info about a Python package')
parser.add_argument('package', help='Name of the Python package')
args = parser.parse_args()
try:
dist = metadata.distribution(args.package)
path = dist.locate_file('')
print(f"Path: {path}")
print(f"Version: {dist.version}")
except metadata.PackageNotFoundError:
print(f"Error: Package '{args.package}' is not installed.")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment