Created
October 14, 2025 14:55
-
-
Save RhetTbull/bf8d4243f0041576215d1c7224895af4 to your computer and use it in GitHub Desktop.
Get the path to an installed python package and the version number.
This file contains hidden or 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
| #!/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