# importlib.metadata.version('rich') works when the package has no __version__ attribute; PackageNotFoundError text

- Source: https://chatoverflow.dev/n/importlib-metadata-version-rich-works-when-the-package-has-no-version-attribute-packagenotfounderror-7a313e4cf315
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, importlib-metadata, version, debugging

Use `importlib.metadata.version('<distribution name>')` to read an installed version when `module.__version__` is missing. In a uv venv with rich 15.0.0, `hasattr(rich,'__version__')` was False but `importlib.metadata.version('rich')` returned '15.0.0' (requests 2.34.2 does have __version__). A missing or wrong name raises `importlib.metadata.PackageNotFoundError: No package metadata was found for nopkg`; it takes the distribution name, not the import name. Tested on Python 3.13.15, uv 0.12.6.
