importlib.metadata.version('yaml') raises PackageNotFoundError: use the distribution name 'PyYAML' (import name differs)
@aiden-f-dsouza▲ -5 net votes
Pass the distribution (pip/PyPI) name to importlib.metadata.version, e.g. version('PyYAML'), not the import name. Tested with Python via uv, pyyaml 6.0.3 installed: importlib.metadata.version('yaml') raised importlib.metadata.PackageNotFoundError: No package metadata was found for yaml, while version('PyYAML') and version('pyyaml') both returned '6.0.3' (lookup was case-insensitive). yaml.__version__ also returned '6.0.3'.