python-poetry/poetry · error · RuntimeError
No lockfile found. Unable to read locked packages
Error message
No lockfile found. Unable to read locked packages
What it means
Raised by Locker._get_lock_data() when self.lock (the poetry.lock path) does not exist on disk. Poetry's solver/installer reads the lockfile to know the exact pinned package set; without it the operation cannot proceed in 'locked' mode. The error is a hard precondition check before any TOML parsing is attempted.
Source
Thrown at src/poetry/packages/locker.py:345
if relevant_project_content:
relevant_content["project"] = relevant_project_content
if group_content:
# For backwards compatibility, we must not add dependency-groups
# if it is empty.
relevant_content["dependency-groups"] = group_content
if relevant_content:
relevant_content["tool"] = {"poetry": relevant_poetry_content}
else:
# For backwards compatibility, we have to put the relevant content
# of the [tool.poetry] section at top level!
relevant_content = relevant_poetry_content
return sha256(json.dumps(relevant_content, sort_keys=True).encode()).hexdigest()
def _get_lock_data(self) -> dict[str, Any]:
if not self.lock.exists():
raise RuntimeError("No lockfile found. Unable to read locked packages")
with self.lock.open("rb") as f:
try:
lock_data = tomllib.load(f)
except tomllib.TOMLDecodeError as e:
raise RuntimeError(f"Unable to read the lock file ({e}).")
# if the lockfile doesn't contain a metadata section at all,
# it probably needs to be rebuilt completely
if "metadata" not in lock_data:
raise RuntimeError(
"The lock file does not have a metadata entry.\n"
"Regenerate the lock file with the `poetry lock` command."
)
metadata = lock_data["metadata"]
if "lock-version" not in metadata:
raise RuntimeError(View on GitHub (pinned to 92b74dcfe3)
Solutions
- Run `poetry lock` to generate poetry.lock for the current pyproject.toml.
- Verify you are in the project root containing pyproject.toml (the lockfile lives alongside it).
- If the lockfile should exist, check git status / .gitignore to confirm it was committed and not deleted.
- For install-only workflows, drop the `--locked` / `--no-update` flags that require an existing lockfile.
Example fix
// before: running in a dir with no poetry.lock $ poetry install RuntimeError: No lockfile found... // after $ poetry lock $ poetry install
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
from poetry.factory import Factory
def ensure_lockfile(project_dir: Path) -> Path:
poetry = Factory().create_poetry(project_dir)
lock = poetry.pyproject_path.parent / "poetry.lock"
if not lock.exists():
raise SystemExit(f"No poetry.lock in {project_dir}. Run `poetry lock` first.")
return lock Prevention
- Commit poetry.lock to version control so fresh clones always have it.
- Gate CI on the existence of poetry.lock before running install.
- Run `poetry lock` immediately after editing dependencies.
- Document the lock-then-install workflow in the project README.
When it happens
Trigger: Calling poetry install, poetry show --locked, or any command that delegates to Locker.locked_packages() / _get_lock_data() in a project directory that has a pyproject.toml but no poetry.lock file (e.g. a fresh clone, or after the lockfile was gitignored/deleted).
Common situations: Fresh checkout of a repo where poetry.lock is not committed; running install before ever running `poetry lock`; CI on a branch that removed the lockfile; wrong working directory so Poetry resolves the project root elsewhere.
Related errors
- Package {package} not found
- Unable to read the lock file ({e}).
- The lock file does not have a metadata entry. Regenerate the
- The lock file is not compatible with the current version of
- The lock file is not compatible with the current version of
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/f8ee269f5bff00a3.json.
Report an issue: GitHub.