{"id":"f45b59dc7d3b1086","repo":"python-poetry/poetry","slug":"unable-to-retrieve-the-package-version-for-name","errorCode":null,"errorMessage":"Unable to retrieve the package version for {name}","messagePattern":"Unable to retrieve the package version for (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/poetry/inspection/info.py","lineNumber":138,"sourceCode":"        \"\"\"\n        Create a new `poetry.core.packages.package.Package` instance using metadata from\n        this instance.\n\n        :param name: Name to use for the package, if not specified name from this\n            instance is used.\n        :param extras: Extras to activate for this package.\n        :param root_dir:  Optional root directory to use for the package. If set,\n            dependency strings will be parsed relative to this directory.\n        \"\"\"\n        name = name or self.name\n\n        if not name:\n            raise RuntimeError(f\"Unable to create package with no name for {root_dir}\")\n\n        if not self.version:\n            # The version could not be determined, so we raise an error since it is\n            # mandatory.\n            raise RuntimeError(f\"Unable to retrieve the package version for {name}\")\n\n        package = Package(\n            name=name,\n            version=self.version,\n            source_type=self._source_type,\n            source_url=self._source_url,\n            source_reference=self._source_reference,\n            yanked=self.yanked,\n        )\n        if self.summary is not None:\n            package.description = self.summary\n        package.root_dir = root_dir\n        package.python_versions = self.requires_python or \"*\"\n        package.files = self.files\n\n        # If this is a local poetry project, we can extract \"richer\" requirement\n        # information, eg: development requirements etc.\n        if root_dir is not None:","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/inspection/info.py#L120-L156","documentation":"Raised by PackageInfo.to_package() at src/poetry/inspection/info.py:135-138 when the version field is falsy. Version is mandatory for a Package, so Poetry aborts with RuntimeError rather than silently using '0.0.0'.","triggerScenarios":"Inspecting a distribution whose metadata has no Version field, or whose version is empty/None. Triggered through PackageInfo.from_path/from_directory → to_package(), e.g. during `poetry add` or dependency resolution on a local package.","commonSituations":"A local package with dynamic versioning that didn't resolve at inspection time (PEP 621 `dynamic = [\"version\"]` without a backend that fills it), a hand-built sdist missing the Version header, or a legacy setup.py without version.","solutions":["Ensure the inspected package's metadata exposes a concrete Version (set version in pyproject.toml [project] or pass it explicitly in setup.py).","If using dynamic versioning, confirm the build backend (e.g. setuptools-git-versioning) actually produces a version at build time.","Rebuild the artifact and verify with `python -m pkginfo ./dist/*.whl` that version is populated."],"exampleFix":"# before\n[project]\nname = \"my_pkg\"\n# no version, no dynamic\n\n# after\n[project]\nname = \"my_pkg\"\nversion = \"0.1.0\"","handlingStrategy":"try-catch","validationCode":"from poetry.inspection.info import PackageInfo\n\ninfo = PackageInfo.from_path(path)\nif not info.version:\n    raise ValueError(f'No version in metadata for {info.name or path}; refusing to convert.')\npkg = info.to_package(root_dir=path)","typeGuard":"def has_version(info: PackageInfo) -> bool:\n    return bool(getattr(info, 'version', None))","tryCatchPattern":"try:\n    pkg = PackageInfo.from_path(path).to_package(root_dir=path)\nexcept RuntimeError as e:\n    if 'retrieve the package version' in str(e):\n        raise ValueError(f'Invalid package at {path}: missing version') from e\n    raise","preventionTips":["Set a concrete version in [project] / setup.py; avoid unresolved dynamic versioning at inspection time.","Use `python -m pkginfo <archive>` to confirm version populates before publishing."],"tags":["metadata","package-info","inspection","versioning","runtime-error"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}