{"record":{"id":"c2475e801e28ef98","repo":"pypa/pip","slug":"invalid-requirement-name-r-exc","errorCode":null,"errorMessage":"Invalid requirement: {name!r}: {exc}","messagePattern":"Invalid requirement: (.+?): (.+?)","errorType":"validation","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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/req/constructors.py#L224-L260","documentation":"Raised by parse_req_from_editable (constructors.py:242) when the project-name portion extracted from an editable requirement string is not a valid PEP 508 requirement name (get_requirement raises InvalidRequirement). The original exception is wrapped as InstallationError with 'Invalid requirement: <name!r>: <exc>'.","triggerScenarios":"The name parsed out of an editable spec (either the PEP 508 name part or the #egg= fragment) contains illegal characters or syntax — e.g. a name with spaces, dots-as-separators misuse, or invalid characters like '@' inside the name portion.","commonSituations":"Typos in the egg fragment ('#egg=My Pkg'); using a name that violates PEP 508; a URL accidentally parsed as the name portion.","solutions":["Correct the project name to a valid PEP 508 name (letters, digits, _, -, .).","Use the exact distribution name from the package's metadata.","Re-run pip install -e '<name> @ <url>' with the corrected name."],"exampleFix":"# before\npip install -e 'git+https://github.com/u/repo.git#egg=My Pkg'\n# after\npip install -e 'my-pkg @ git+https://github.com/u/repo.git'","handlingStrategy":"validation","validationCode":"from pip._vendor.packaging.requirements import Requirement, InvalidRequirement\nimport re\n\ndef editable_name_is_valid(line: str) -> bool:\n    # Extract name from PEP 508 form or #egg=...\n    m = re.match(r'^\\s*([^@\\s]+)\\s*@', line)\n    name = m.group(1) if m else None\n    if name is None and '#egg=' in line:\n        name = line.split('#egg=', 1)[1].split('&')[0].split(';')[0]\n    if not name:\n        return False\n    try:\n        Requirement(name)\n        return True\n    except InvalidRequirement:\n        return False","typeGuard":"from pip._vendor.packaging.requirements import Requirement, InvalidRequirement\n\ndef is_valid_project_name(name: str) -> bool:\n    try:\n        Requirement(name)\n        return True\n    except InvalidRequirement:\n        return False","tryCatchPattern":"from subprocess import run, CalledProcessError\ntry:\n    run([\"pip\", \"install\", \"-e\", target], check=True)\nexcept CalledProcessError:\n    # Correct the name to a valid PEP 508 identifier and retry.\n    run([\"pip\", \"install\", \"-e\", f\"{clean_name} @ {url}\"], check=True)","preventionTips":["Use the canonical distribution name from the package's metadata for editable installs.","Validate the name part with packaging.requirements before invoking pip.","Avoid spaces and special characters in #egg= fragments and name@url forms."],"tags":["editable","pep508","requirement-name","validation","pip"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}