{"id":"530bddd32a9b0b5c","repo":"pypa/pip","slug":"invalid-requirement-name-strip-r-exc","errorCode":null,"errorMessage":"Invalid requirement: {name.strip()!r}: {exc}","messagePattern":"Invalid requirement: (.+?): (.+?)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/req/constructors.py","lineNumber":349,"sourceCode":"    )\n    return path_to_url(path)\n\n\ndef parse_req_from_line(name: str, line_source: str | None) -> RequirementParts:\n    if is_url(name):\n        marker_sep = \"; \"\n    else:\n        marker_sep = \";\"\n    if marker_sep in name:\n        name, markers_as_string = name.split(marker_sep, 1)\n        markers_as_string = markers_as_string.strip()\n        if not markers_as_string:\n            markers = None\n        else:\n            try:\n                markers = Marker(markers_as_string)\n            except InvalidMarker as exc:\n                raise InstallationError(f\"Invalid requirement: {name.strip()!r}: {exc}\")\n    else:\n        markers = None\n    name = name.strip()\n    req_as_string = None\n    path = os.path.normpath(os.path.abspath(name))\n    link = None\n\n    if is_url(name):\n        link = Link(name)\n        extras: set[str] = set()\n    else:\n        p, extras = strip_extras(path)\n        url = _get_url_from_path(p, name)\n        if url is not None:\n            link = Link(url)\n\n    # it's a local file, dir, or url\n    if link:","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/req/constructors.py#L331-L367","documentation":"Raised by parse_req_from_line() when the environment marker portion of a requirement line (after `;`) fails to parse as a valid PEP 508 marker. The marker string is parsed with Marker() at constructors.py:347; an InvalidMarker exception is caught and re-raised as an InstallationError showing the requirement name and the underlying parse error.","triggerScenarios":"A requirement line like `package ; python_version = \"3.10\"` (using `=` instead of `==` inside the marker), `package ; os_name is \"posix\"` with invalid token, or any malformed marker expression. The split happens on `;` (or `; ` for URLs).","commonSituations":"Typos in marker operators (= vs ==). Unsupported marker fields. Mismatched quotes. Copy-pasting markers from sources that mangled quote characters.","solutions":["Read the marker error in the message and correct the operator — markers use `==`, `!=`, `<`, `<=`, `>`, `>=`, `in`, `not in`.","Ensure marker variable names are valid PEP 508 environment markers (python_version, sys_platform, platform_machine, etc.).","Quote string literals with single or double quotes consistently.","Test the marker in isolation: `python -c \"from packaging.markers import Marker; Marker('python_version == \\\"3.10\\\"')\"`."],"exampleFix":"# before\npackage ; python_version = \"3.10\"\n# after\npackage ; python_version == \"3.10\"","handlingStrategy":"validation","validationCode":"from packaging.markers import Marker, InvalidMarker\n\ndef validate_marker(marker_str: str) -> Marker:\n    try:\n        return Marker(marker_str)\n    except InvalidMarker as e:\n        raise ValueError(f\"Invalid marker {marker_str!r}: {e}\") from e\n\n# split requirement on ';' and validate the marker half before pip","typeGuard":"from packaging.markers import Marker, InvalidMarker\n\ndef is_valid_marker(s: str) -> bool:\n    try:\n        Marker(s)\n        return True\n    except InvalidMarker:\n        return False","tryCatchPattern":"null","preventionTips":["Use == (not =) inside marker comparisons.","Stick to PEP 508 marker variables (python_version, sys_platform, etc.).","Quote string literals consistently in markers.","Validate markers standalone before committing requirements files."],"tags":["requirements","pep508","markers","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}