{"record":{"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":"validation","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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/req/constructors.py#L331-L367","documentation":"While parsing a requirement from a line, pip successfully split off the marker portion (after ';') but failed to construct a packaging Marker object from it. The marker must follow PEP 508 environment marker syntax, and an InvalidMarker exception was caught and re-raised as an InstallationError.","triggerScenarios":"A requirement line with a malformed environment marker such as 'package ; python_version > 3.8' (missing quotes around the value) or 'package ; bogus_marker == x'. The marker string is passed to packaging.markers.Marker() which rejects it.","commonSituations":"Using unquoted marker values (python_version > 3.8 instead of python_version > \"3.8\"). Typo in marker variable names. Copy-pasting from rendered docs that converted straight quotes to smart quotes. Using markers unsupported by the installed packaging library version.","solutions":["Quote all marker values: use python_version > \"3.8\" not python_version > 3.8","Verify marker variable names against PEP 508 (e.g. python_version, sys_platform, platform_machine)","Test the marker in isolation: python -c \"from packaging.markers import Marker; Marker('python_version > \\\"3.8\\\"')\"","Check for smart/curly quotes introduced by copy-paste and replace with straight quotes"],"exampleFix":"# before\npackage ; python_version > 3.8\n\n# after\npackage ; python_version > \"3.8\"","handlingStrategy":"validation","validationCode":"from pip._vendor.packaging.markers import Marker, InvalidMarker\n\ndef validate_marker(marker_str: str) -> bool:\n    try:\n        Marker(marker_str)\n        return True\n    except InvalidMarker:\n        return False\n\nif \";\" in req_line:\n    _, marker_part = req_line.split(\";\", 1)\n    if not validate_marker(marker_part.strip()):\n        print(f\"Invalid marker: {marker_part!r}\")","typeGuard":"from pip._vendor.packaging.markers import Marker, InvalidMarker\n\ndef is_valid_marker(marker_str: str) -> bool:\n    \"\"\"Type guard: True if marker_str is a valid PEP 508 marker.\"\"\"\n    try:\n        Marker(marker_str)\n        return True\n    except InvalidMarker:\n        return False","tryCatchPattern":"from pip._internal.exceptions import InstallationError\n\ntry:\n    parts = parse_req_from_line(line, source)\nexcept InstallationError as e:\n    if \"Invalid requirement\" in str(e):\n        # log and skip or fix the marker\n        logger.error(\"Skipping line with bad marker: %s\", line)\n    else:\n        raise","preventionTips":["Always quote marker values: python_version > \"3.8\" not python_version > 3.8","Validate markers with packaging.markers.Marker() before adding them to requirements files","Beware copy-paste from rendered documentation that converts straight quotes to smart quotes"],"tags":["pip","marker","pep508","parsing","requirements"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}