{"id":"f8ee269f5bff00a3","repo":"python-poetry/poetry","slug":"no-lockfile-found-unable-to-read-locked-packages","errorCode":null,"errorMessage":"No lockfile found. Unable to read locked packages","messagePattern":"No lockfile found\\. Unable to read locked packages","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/poetry/packages/locker.py","lineNumber":345,"sourceCode":"        if relevant_project_content:\n            relevant_content[\"project\"] = relevant_project_content\n        if group_content:\n            # For backwards compatibility, we must not add dependency-groups\n            # if it is empty.\n            relevant_content[\"dependency-groups\"] = group_content\n\n        if relevant_content:\n            relevant_content[\"tool\"] = {\"poetry\": relevant_poetry_content}\n        else:\n            # For backwards compatibility, we have to put the relevant content\n            # of the [tool.poetry] section at top level!\n            relevant_content = relevant_poetry_content\n\n        return sha256(json.dumps(relevant_content, sort_keys=True).encode()).hexdigest()\n\n    def _get_lock_data(self) -> dict[str, Any]:\n        if not self.lock.exists():\n            raise RuntimeError(\"No lockfile found. Unable to read locked packages\")\n\n        with self.lock.open(\"rb\") as f:\n            try:\n                lock_data = tomllib.load(f)\n            except tomllib.TOMLDecodeError as e:\n                raise RuntimeError(f\"Unable to read the lock file ({e}).\")\n\n        # if the lockfile doesn't contain a metadata section at all,\n        # it probably needs to be rebuilt completely\n        if \"metadata\" not in lock_data:\n            raise RuntimeError(\n                \"The lock file does not have a metadata entry.\\n\"\n                \"Regenerate the lock file with the `poetry lock` command.\"\n            )\n\n        metadata = lock_data[\"metadata\"]\n        if \"lock-version\" not in metadata:\n            raise RuntimeError(","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/packages/locker.py#L327-L363","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: running in a dir with no poetry.lock\n$ poetry install\nRuntimeError: No lockfile found...\n\n// after\n$ poetry lock\n$ poetry install","handlingStrategy":"validation","validationCode":"from pathlib import Path\nfrom poetry.factory import Factory\n\ndef ensure_lockfile(project_dir: Path) -> Path:\n    poetry = Factory().create_poetry(project_dir)\n    lock = poetry.pyproject_path.parent / \"poetry.lock\"\n    if not lock.exists():\n        raise SystemExit(f\"No poetry.lock in {project_dir}. Run `poetry lock` first.\")\n    return lock","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["lockfile","setup","poetry"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}