python-poetry/poetry · error · ValueError
Could not find a matching version of package {name}
Error message
Could not find a matching version of package {name} What it means
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.
Source
Thrown at src/poetry/console/commands/init.py:457
return result
def _find_best_version_for_package(
self,
name: str,
required_version: str | None = None,
allow_prereleases: bool | None = None,
source: str | None = None,
) -> tuple[str, str]:
from poetry.version.version_selector import VersionSelector
selector = VersionSelector(self._get_pool())
package = selector.find_best_candidate(
name, required_version, allow_prereleases=allow_prereleases, source=source
)
if not package:
# TODO: find similar
raise ValueError(f"Could not find a matching version of package {name}")
version = package.version.without_local()
return package.pretty_name, f"^{version.to_string()}"
def _parse_requirements(self, requirements: list[str]) -> list[dict[str, Any]]:
from poetry.core.pyproject.exceptions import PyProjectError
try:
cwd = self.poetry.file.path.parent
artifact_cache = self.poetry.pool.artifact_cache
except (PyProjectError, RuntimeError):
cwd = Path.cwd()
artifact_cache = self._get_pool().artifact_cache
parser = RequirementsParser(
artifact_cache=artifact_cache,
env=self.env if isinstance(self, EnvCommand) else None,
cwd=cwd,View on GitHub (pinned to 92b74dcfe3)
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.
Example fix
# before poetry add requets # after poetry add requests
Defensive patterns
Strategy: try-catch
Validate before calling
from poetry.repositories.pypi_repository import PyPiRepository
repo = PyPiRepository(config=...)
packages = repo.search("requests") # or repo.package(name, version)
if not packages:
raise SystemExit("package not found on the configured pool") Type guard
def package_exists(pool, name: str, constraint: str | None = None) -> bool:
from poetry.version.version_selector import VersionSelector
selector = VersionSelector(pool)
return selector.find_best_candidate(name, constraint) is not None Try / catch
try:
name, version = cmd._find_best_version_for_package(name, constraint)
except ValueError:
# correct name, add source, or loosen constraint
... Prevention
- Validate package names against the registry before scripting installs.
- Configure private sources before referencing their packages.
- Loosen constraints and allow pre-releases when appropriate.
When it happens
Trigger: 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.
Common situations: Private index not configured; package renamed or yanked; pin like `>=2` when only `1.x` is published; network/proxy blocking the registry.
Related errors
- Invalid package definition.
- The following packages were not found: {', '.join(sorted(not
- Failed to install required Poetry plugins
- Redirects are not supported. Is the URL missing a trailing s
- HTTP Error {e.response.status_code}: {e.response.reason} | {
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/8f13d2b7f72cecbb.json.
Report an issue: GitHub.