python-poetry/poetry · error · ValueError
The following packages were not found: {', '.join(sorted(not
Error message
The following packages were not found: {', '.join(sorted(not_found))} What it means
ValueError from `poetry remove` (remove.py:162-166) when one or more named packages were not located in any dependency section (`[tool.poetry.dependencies]`, `[tool.poetry.group.*.dependencies]`, or `[dependency-groups]`). `removed` accumulates found packages; the set difference yields the missing ones.
Source
Thrown at src/poetry/console/commands/remove.py:164
packages=packages,
standard_section=groups_content[group],
poetry_section={},
group_name=group,
)
)
if not groups_content[group]:
del groups_content[group]
if group not in groups_content and group not in poetry_groups_content:
self._remove_references_to_group(group, content)
if "group" in poetry_content and not poetry_content["group"]:
del poetry_content["group"]
if "dependency-groups" in content and not content["dependency-groups"]:
del content["dependency-groups"]
not_found = set(packages).difference(removed)
if not_found:
raise ValueError(
"The following packages were not found: " + ", ".join(sorted(not_found))
)
# Refresh the locker
self.poetry.locker.set_pyproject_data(content)
self.installer.set_locker(self.poetry.locker)
self.installer.set_package(self.poetry.package)
self.installer.dry_run(self.option("dry-run", False))
self.installer.verbose(self.io.is_verbose())
self.installer.update(True)
self.installer.execute_operations(not self.option("lock"))
self.installer.whitelist(removed)
status = self.installer.run()
if not self.option("dry-run") and status == 0:
self.poetry.file.write(content)
View on GitHub (pinned to 92b74dcfe3)
Solutions
- Confirm the exact name with `poetry show` or by inspecting pyproject.toml.
- Use the canonical (normalized) name as declared.
- If it is a transitive dependency, remove the parent that requires it instead.
Example fix
# before poetry remove requets # after poetry remove requests
Defensive patterns
Strategy: validation
Validate before calling
from poetry.factory import Factory
poetry = Factory().create_poetry()
declared = {d.name for d in poetry.package.all_requires}
requested = {"requests"}
missing = requested - declared
if missing:
raise SystemExit(f"not declared: {sorted(missing)}") Type guard
def is_declared_dependency(poetry, name: str) -> bool:
from packaging.utils import canonicalize_name
target = canonicalize_name(name)
return any(canonicalize_name(d.name) == target
for d in poetry.package.all_requires) Prevention
- Pull removal lists from pyproject.toml, not memory.
- Canonicalize names before comparison.
- Re-run `poetry lock` after structural changes.
When it happens
Trigger: Running `poetry remove foes` when only `requests` is declared; removing a transitive dependency that is not a direct requirement; case mismatches.
Common situations: Typos; package already removed; package present only in the lock file (transitive) — `remove` only operates on direct requirements.
Related errors
- Invalid package definition.
- Setting {self.argument('key')} does not exist
- You can only pass one value.
- "{value}" is an invalid value for {key}
- Group(s) not found: {', '.join(message_parts)}
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/2bfc7500ee604499.json.
Report an issue: GitHub.