{"record":{"id":"1d0df2b26ef77a09","repo":"pypa/pip","slug":"could-not-split-options-options-str","errorCode":null,"errorMessage":"Could not split options: {options_str}","messagePattern":"Could not split options: (.+?)","errorType":"validation","errorClass":"OptionParsingError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/req/req_file.py","lineNumber":442,"sourceCode":"\n\ndef get_line_parser(finder: PackageFinder | None) -> LineParser:\n    def parse_line(line: str) -> tuple[str, Values]:\n        # Build new parser for each line since it accumulates appendable\n        # options.\n        parser = build_parser()\n        defaults = parser.get_default_values()\n        defaults.index_url = None\n        if finder:\n            defaults.format_control = finder.format_control\n            defaults.release_control = finder.release_control\n\n        args_str, options_str = break_args_options(line)\n\n        try:\n            options = shlex.split(options_str)\n        except ValueError as e:\n            raise OptionParsingError(f\"Could not split options: {options_str}\") from e\n\n        opts, _ = parser.parse_args(options, defaults)\n\n        return args_str, opts\n\n    return parse_line\n\n\ndef break_args_options(line: str) -> tuple[str, str]:\n    \"\"\"Break up the line into an args and options string.  We only want to shlex\n    (and then optparse) the options, not the args.  args can contain markers\n    which are corrupted by shlex.\n    \"\"\"\n    tokens = line.split(\" \")\n    args = []\n    options = tokens[:]\n    for token in tokens:\n        if token.startswith((\"-\", \"--\")):","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/req/req_file.py#L424-L460","documentation":"pip uses shlex.split() to tokenize the options portion of a requirements file line, and it failed with a ValueError. This almost always means there are unbalanced quotes in the options string — shlex cannot close an unterminated quoted segment.","triggerScenarios":"A requirements file line like 'requests --hash=\"sha256:abc...' where the closing double quote is missing, or '--index-url=\\'https://...' with an unterminated single quote. shlex.split raises ValueError and it is wrapped in OptionParsingError then RequirementsFileParseError.","commonSituations":"Unterminated quotes after editing a hash or URL. Backslash escaping gone wrong in Windows paths. Copy-paste that dropped a trailing quote. Multi-line values that were not properly joined.","solutions":["Check for unbalanced single or double quotes in the options portion of the line","Ensure every opening quote has a matching closing quote","On Windows, avoid backslashes in paths or escape them properly; prefer forward slashes","If the option value has no spaces, you can often drop the quotes entirely"],"exampleFix":"# before — requirements.txt\nrequests --hash=\"sha256:abc123\n\n# after\nrequests --hash=\"sha256:abc123\"","handlingStrategy":"validation","validationCode":"import shlex\n\ndef validate_options_quoting(line: str) -> bool:\n    \"\"\"Returns True if the options portion of the line has balanced quotes.\"\"\"\n    tokens = line.split(\" \")\n    options = []\n    for t in tokens:\n        if t.startswith(\"-\"):\n            break\n    options_str = \" \".join(t for t in tokens if t not in options)\n    try:\n        shlex.split(options_str)\n        return True\n    except ValueError:\n        return False","typeGuard":"import shlex\n\ndef has_balanced_quotes(options_str: str) -> bool:\n    \"\"\"Type guard: True if shlex can split the options string without error.\"\"\"\n    try:\n        shlex.split(options_str)\n        return True\n    except ValueError:\n        return False","tryCatchPattern":"from pip._internal.exceptions import RequirementsFileParseError\nfrom pip._internal.req.req_file import parse_requirements\n\ntry:\n    list(parse_requirements(\"requirements.txt\", session))\nexcept RequirementsFileParseError as e:\n    if \"Could not split options\" in str(e):\n        print(\"Fix unbalanced quotes in the options portion of the line\")\n    else:\n        raise","preventionTips":["Ensure every opening quote in requirements file options has a matching close","On Windows, use forward slashes in paths or escape backslashes properly","Drop quotes around option values that contain no spaces"],"tags":["pip","requirements-file","shlex","quoting","parsing"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}