{"record":{"id":"c72263d05ece910e","repo":"pypa/pip","slug":"invalid-requirement-line-e-msg","errorCode":null,"errorMessage":"Invalid requirement: {line}\n{e.msg}","messagePattern":"Invalid requirement: (.+?)\n(.+?)","errorType":"validation","errorClass":"RequirementsFileParseError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/req/req_file.py","lineNumber":415,"sourceCode":"                    req_path, nested_constraint, [new_parsed_files, *parsed_files_stack]\n                )\n            else:\n                yield line\n\n    def _parse_file(\n        self, filename: str, constraint: bool\n    ) -> Generator[ParsedLine, None, None]:\n        _, content = get_file_content(filename, self._session, constraint=constraint)\n\n        lines_enum = preprocess(content)\n\n        for line_number, line in lines_enum:\n            try:\n                args_str, opts = self._line_parser(line)\n            except OptionParsingError as e:\n                # add offending line\n                msg = f\"Invalid requirement: {line}\\n{e.msg}\"\n                raise RequirementsFileParseError(msg)\n\n            yield ParsedLine(\n                filename,\n                line_number,\n                args_str,\n                opts,\n                constraint,\n            )\n\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:","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/req/req_file.py#L397-L433","documentation":"While parsing a line in a requirements file, the per-line option parser (optparse) raised an OptionParsingError. This happens when the line contains options that pip does not recognize or that are malformed. The error wraps the offending line text and the parser's error message into a RequirementsFileParseError.","triggerScenarios":"A requirements file line with an unrecognized option flag, e.g. 'requests --fnd-links https://example.com' (typo for --find-links), or an option used in a context where it is not allowed. The OptionParsingError is caught in _parse_file and re-raised.","commonSituations":"Typo in option names. Using an option not in the SUPPORTED_OPTIONS list for that context. Deprecated options removed in newer pip versions. Copy-paste from documentation with formatting artifacts.","solutions":["Check the offending line against pip's supported requirements-file options","Look for typos in option flags (e.g. --fnd-links vs --find-links, --index-ur vs --index-url)","Verify the option is valid in the context (some options only apply to requirement lines, not option-only lines)","Upgrade pip if the option was recently added and your version is old"],"exampleFix":"# before — requirements.txt\nrequests --fnd-links https://example.com/wheels/\n\n# after\nrequests --find-links https://example.com/wheels/","handlingStrategy":"try-catch","validationCode":"from pip._internal.req.req_file import build_parser, break_args_options\nimport shlex\n\ndef validate_req_line(line: str) -> bool:\n    try:\n        args_str, options_str = break_args_options(line)\n        options = shlex.split(options_str)\n        parser = build_parser()\n        parser.parse_args(options, parser.get_default_values())\n        return True\n    except Exception:\n        return False","typeGuard":"from pip._internal.req.req_file import build_parser, break_args_options, OptionParsingError\nimport shlex\n\ndef is_valid_req_file_line(line: str) -> bool:\n    \"\"\"Type guard: True if the line parses without OptionParsingError.\"\"\"\n    try:\n        args_str, options_str = break_args_options(line)\n        parser = build_parser()\n        parser.parse_args(shlex.split(options_str), parser.get_default_values())\n        return True\n    except Exception:\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 \"Invalid requirement\" in str(e):\n        print(f\"Fix the malformed line: {e}\")\n    else:\n        raise","preventionTips":["Check option names against pip's supported list in requirements files","Watch for typos like --fnd-links instead of --find-links","Validate requirements files with a linter or dry-run parse before CI"],"tags":["pip","requirements-file","optparse","options","parsing"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}