{"id":"7ce0055616222349","repo":"pypa/pip","slug":"file-does-not-contain-name-r-metadata-scriptfi","errorCode":null,"errorMessage":"File does not contain {name!r} metadata: {scriptfile!r}","messagePattern":"File does not contain (.+?) metadata: (.+?)","errorType":"exception","errorClass":"PEP723Exception","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/req/pep723.py","lineNumber":37,"sourceCode":"\n    name = \"script\"\n    matches = list(\n        filter(lambda m: m.group(\"type\") == name, re.finditer(REGEX, script))\n    )\n\n    if len(matches) > 1:\n        raise PEP723Exception(f\"Multiple {name!r} blocks found in {scriptfile!r}\")\n    elif len(matches) == 1:\n        content = \"\".join(\n            line[2:] if line.startswith(\"# \") else line[1:]\n            for line in matches[0].group(\"content\").splitlines(keepends=True)\n        )\n        try:\n            metadata = tomllib.loads(content)\n        except Exception as exc:\n            raise PEP723Exception(f\"Failed to parse TOML in {scriptfile!r}\") from exc\n    else:\n        raise PEP723Exception(\n            f\"File does not contain {name!r} metadata: {scriptfile!r}\"\n        )\n\n    return metadata\n","sourceCodeStart":19,"sourceCodeEnd":42,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/req/pep723.py#L19-L42","documentation":"Raised by pep723_metadata() when a script file is processed for PEP 723 inline metadata but contains zero `# /// script` blocks (the else branch at pep723.py:37). pip was asked to read PEP 723 metadata from the file, but none exists, so it cannot determine the script's dependencies.","triggerScenarios":"Running a PEP 723-aware code path (e.g. `pip run script.py`) on a plain Python script that has no `# /// script` block. The regex finds zero matches of type 'script'.","commonSituations":"Passing a regular script to a tool that requires inline metadata. Forgetting to add the metadata block when migrating to pip run. A script that intentionally has no deps but the tooling still requires the block.","solutions":["If the script needs dependencies declared inline, add a `# /// script` block with a `dependencies` array.","If the script has no external dependencies, either add an empty block or use a normal `python script.py` invocation after installing deps separately.","Verify the block uses the exact marker `# /// script` (lowercase, no extra text on the marker line)."],"exampleFix":"# before\n# (script with no metadata block)\nimport requests\n# after\n# /// script\n# dependencies = [\"requests\"]\n# ///\nimport requests","handlingStrategy":"validation","validationCode":"import re\n\nPEP723_RE = r\"(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\\s(?P<content>(^#(| .*)$\\s)+)^# ///$\"\n\ndef has_pep723_block(scriptfile: str) -> bool:\n    with open(scriptfile, encoding=\"utf8\") as f:\n        script = f.read()\n    return any(m.group(\"type\") == \"script\" for m in re.finditer(PEP723_RE, script))\n\n# before invoking a PEP 723 code path:\nif not has_pep723_block(scriptfile):\n    raise ValueError(f\"{scriptfile} has no PEP 723 script metadata block\")","typeGuard":"null","tryCatchPattern":"from pip._internal.req.pep723 import pep723_metadata, PEP723Exception\n\ntry:\n    meta = pep723_metadata(scriptfile)\nexcept PEP723Exception as e:\n    if \"does not contain\" in e.msg:\n        meta = {}  # treat as no inline deps\n    else:\n        raise","preventionTips":["Add a `# /// script` block (even if just with `dependencies = []`) to scripts meant for PEP 723 tooling.","Use the exact marker `# /// script` on its own line.","For scripts without external deps, prefer plain `python script.py` over PEP 723 tooling."],"tags":["pep723","script","toml","metadata"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}