python-poetry/poetry · error · ValueError

Package {package} not found

Error message

Package {package} not found

What it means

ValueError from `_display_single_package_information` (show.py:187-188) when the requested package name (canonicalized) is not present among the locked packages. `poetry show <pkg>` only displays packages recorded in `poetry.lock`.

Source

Thrown at src/poetry/console/commands/show.py:188

        if self.poetry.package.name == POETRY_SYSTEM_PROJECT_NAME:
            return "poetry self lock"

        return "poetry lock"

    def _display_single_package_information(
        self, package: str, locked_repository: Repository
    ) -> int:
        locked_packages = locked_repository.packages
        canonicalized_package = canonicalize_name(package)
        pkg = None

        for locked in locked_packages:
            if locked.name == canonicalized_package:
                pkg = locked
                break

        if not pkg:
            raise ValueError(f"Package {package} not found")

        required_by = reverse_deps(pkg, locked_repository)

        if self.option("tree"):
            if self.option("why"):
                # The default case if there's no reverse dependencies is to query
                # the subtree for pkg but if any rev-deps exist we'll query for each
                # of them in turn
                packages = [pkg]
                if required_by:
                    packages = [
                        p for p in locked_packages for r in required_by if p.name == r
                    ]
                else:
                    # if no rev-deps exist we'll make this clear as it can otherwise
                    # look very odd for packages that also have no or few direct
                    # dependencies
                    self.io.write_line(f"Package {package} is a direct dependency.")

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. Refresh the lock file: `poetry lock --no-update` then retry.
  2. Verify the name with `poetry show` (lists all locked packages).
  3. Add the package with `poetry add` if it should be a direct dependency.

Example fix

# before
poetry show requets
# after
poetry show requests
Defensive patterns

Strategy: validation

Validate before calling

from poetry.factory import Factory
from packaging.utils import canonicalize_name
poetry = Factory().create_poetry()
locked = {p.name for p in poetry.locker.locked_repository().packages}
if canonicalize_name("requests") not in locked:
    raise SystemExit("package not in lock file")

Type guard

def in_lockfile(poetry, name: str) -> bool:
    from packaging.utils import canonicalize_name
    target = canonicalize_name(name)
    return any(p.name == target for p in poetry.locker.locked_repository().packages)

Prevention

When it happens

Trigger: Running `poetry show foes` for a package not in the lock file; querying before `poetry lock` has been run; lock file out of date.

Common situations: Typos; package is a transitive dep not surfaced in the lock subset; lock file stale after pyproject edits.

Related errors


AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04). Data as JSON: /data/errors/e27c360171f0c729.json. Report an issue: GitHub.