{"id":"8f13d2b7f72cecbb","repo":"python-poetry/poetry","slug":"could-not-find-a-matching-version-of-package-name","errorCode":null,"errorMessage":"Could not find a matching version of package {name}","messagePattern":"Could not find a matching version of package (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/poetry/console/commands/init.py","lineNumber":457,"sourceCode":"        return result\n\n    def _find_best_version_for_package(\n        self,\n        name: str,\n        required_version: str | None = None,\n        allow_prereleases: bool | None = None,\n        source: str | None = None,\n    ) -> tuple[str, str]:\n        from poetry.version.version_selector import VersionSelector\n\n        selector = VersionSelector(self._get_pool())\n        package = selector.find_best_candidate(\n            name, required_version, allow_prereleases=allow_prereleases, source=source\n        )\n\n        if not package:\n            # TODO: find similar\n            raise ValueError(f\"Could not find a matching version of package {name}\")\n\n        version = package.version.without_local()\n        return package.pretty_name, f\"^{version.to_string()}\"\n\n    def _parse_requirements(self, requirements: list[str]) -> list[dict[str, Any]]:\n        from poetry.core.pyproject.exceptions import PyProjectError\n\n        try:\n            cwd = self.poetry.file.path.parent\n            artifact_cache = self.poetry.pool.artifact_cache\n        except (PyProjectError, RuntimeError):\n            cwd = Path.cwd()\n            artifact_cache = self._get_pool().artifact_cache\n\n        parser = RequirementsParser(\n            artifact_cache=artifact_cache,\n            env=self.env if isinstance(self, EnvCommand) else None,\n            cwd=cwd,","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/init.py#L439-L475","documentation":"ValueError from `_find_best_version_for_package` (init.py:455-457) when `VersionSelector.find_best_candidate` returns None — no package on the configured pool matches the name (and constraint). Used by `poetry init` / `poetry add` interactive flows to validate a requested dependency.","triggerScenarios":"Typoed package name; package exists only on a source not in the pool; required version constraint excludes every published release; prereleases exist but `allow-prereleases` is false.","commonSituations":"Private index not configured; package renamed or yanked; pin like `>=2` when only `1.x` is published; network/proxy blocking the registry.","solutions":["Verify the name on the registry (PyPI or configured source) and correct typos.","Add the source: `poetry source add <name> <url>` then retry.","Loosen or fix the version constraint; pass `--allow-prereleases` if only pre-releases exist.","Check network/proxy reachability of the index URL."],"exampleFix":"# before\npoetry add requets\n# after\npoetry add requests","handlingStrategy":"try-catch","validationCode":"from poetry.repositories.pypi_repository import PyPiRepository\nrepo = PyPiRepository(config=...)\npackages = repo.search(\"requests\")  # or repo.package(name, version)\nif not packages:\n    raise SystemExit(\"package not found on the configured pool\")","typeGuard":"def package_exists(pool, name: str, constraint: str | None = None) -> bool:\n    from poetry.version.version_selector import VersionSelector\n    selector = VersionSelector(pool)\n    return selector.find_best_candidate(name, constraint) is not None","tryCatchPattern":"try:\n    name, version = cmd._find_best_version_for_package(name, constraint)\nexcept ValueError:\n    # correct name, add source, or loosen constraint\n    ...","preventionTips":["Validate package names against the registry before scripting installs.","Configure private sources before referencing their packages.","Loosen constraints and allow pre-releases when appropriate."],"tags":["dependencies","resolver","network"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}