{"id":"c2475e801e28ef98","repo":"pypa/pip","slug":"invalid-requirement-name-r-exc","errorCode":null,"errorMessage":"Invalid requirement: {name!r}: {exc}","messagePattern":"Invalid requirement: (.+?): (.+?)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/req/constructors.py","lineNumber":242,"sourceCode":"    return msg\n\n\n@dataclass(frozen=True)\nclass RequirementParts:\n    requirement: Requirement | None\n    link: Link | None\n    markers: Marker | None\n    extras: set[str]\n\n\ndef parse_req_from_editable(editable_req: str) -> RequirementParts:\n    name, url, extras_override = parse_editable(editable_req)\n\n    if name is not None:\n        try:\n            req: Requirement | None = get_requirement(name)\n        except InvalidRequirement as exc:\n            raise InstallationError(f\"Invalid requirement: {name!r}: {exc}\")\n    else:\n        req = None\n\n    link = Link(url)\n\n    return RequirementParts(req, link, None, extras_override)\n\n\n# ---- The actual constructors follow ----\n\n\ndef install_req_from_editable(\n    editable_req: str,\n    comes_from: InstallRequirement | str | None = None,\n    *,\n    isolated: bool = False,\n    hash_options: dict[str, list[str]] | None = None,\n    constraint: bool = False,","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/req/constructors.py#L224-L260","documentation":"Raised by parse_req_from_editable() when the project NAME portion of an editable requirement (parsed out of the URL/egg fragment or the `name @ url` form) is not a valid PEP 508 requirement name. After extracting the name at constructors.py:240, get_requirement(name) fails with InvalidRequirement and pip wraps it as an InstallationError.","triggerScenarios":"An editable spec where the inferred or supplied name contains illegal characters, e.g. `pip install -e \"my pkg @ git+https://...\"` (space in name), a name with leading digits, or a name fragment with invalid PEP 508 syntax. The name is parsed independently of the URL.","commonSituations":"Typos in the #egg= fragment. Names containing hyphens mixed with uppercase mismatches. Copy-pasting a display name rather than the normalized distribution name.","solutions":["Inspect the name shown in the error and normalize it to a valid PEP 508 name (letters, digits, hyphens, underscores, dots; must not start with a digit).","Re-issue the editable install with the corrected name in either `name @ url` or `#egg=name` form.","Avoid spaces and special characters in the egg fragment."],"exampleFix":"# before\npip install -e \"my pkg @ git+https://github.com/org/repo.git\"\n# after\npip install -e \"my-pkg @ git+https://github.com/org/repo.git\"","handlingStrategy":"validation","validationCode":"from packaging.requirements import Requirement, InvalidRequirement\n\ndef validate_editable_name(name: str) -> str:\n    try:\n        Requirement(name)\n    except InvalidRequirement as e:\n        raise ValueError(f\"Invalid editable requirement name {name!r}: {e}\") from e\n    return name","typeGuard":"from packaging.requirements import Requirement, InvalidRequirement\n\ndef is_valid_requirement_name(name: str) -> bool:\n    try:\n        Requirement(name)\n        return True\n    except InvalidRequirement:\n        return False","tryCatchPattern":"from pip._internal.exceptions import InstallationError\n\ntry:\n    parts = parse_req_from_editable(spec)\nexcept InstallationError as e:\n    if \"Invalid requirement\" in str(e):\n        # log and surface a user-friendly message\n        ...\n    raise","preventionTips":["Use normalized distribution names (lowercase, ASCII, hyphens/underscores).","Avoid spaces and punctuation in egg fragments.","Validate the name component with packaging before issuing pip commands."],"tags":["editable","pep508","requirements","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}