{"id":"158de07c441fa226","repo":"pypa/pip","slug":"invalid-requirement-line-n-e-msg","errorCode":null,"errorMessage":"Invalid requirement: {line}\\n{e.msg}","messagePattern":"Invalid requirement: (.+?)\\\\n(.+?)","errorType":"exception","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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/req/req_file.py#L397-L433","documentation":"RequirementsFileParseError raised while parsing a single line of a requirements/constraints file: the line could not be split into args + options by pip's optparse-based line parser (OptionParsingError). The offending line is echoed along with the parser's message so the user can locate the typo.","triggerScenarios":"Running 'pip install -r requirements.txt' where a line uses an unknown option flag (e.g. '--foo'), a malformed option (missing value after '--index-url'), or text that optparse rejects. Anything in the options portion after the first '--'-prefixed token gets parsed by optparse.","commonSituations":"Typos in option names ('--find-links' misspelled); copy-pasting a shell-style '--index-url=http://...' that optparse still accepts but a missing '=' elsewhere breaks; environment-specific options from a teammate's machine; trailing option tokens a user thought were part of the package name.","solutions":["Read {line} and {e.msg} from the error: they pinpoint the bad line and the parser complaint.","Cross-check the option name against pip's supported requirement-line options (--index-url, --extra-index-url, --find-links, --hash, etc.).","Quote values that contain spaces and ensure each '--opt=value' or '--opt value' pair is complete.","Remove the offending option or move it to the CLI invocation if it isn't valid in a requirements file."],"exampleFix":"# before — requirements.txt\nrequests --find-lins https://example.com\n\n# after\nrequests --find-links https://example.com","handlingStrategy":"validation","validationCode":"from pip._internal.req.req_file import get_line_parser, OptionParsingError\ndef validate_line(line: str, finder=None) -> bool:\n    try:\n        get_line_parser(finder)(line)\n        return True\n    except OptionParsingError as e:\n        print(f'bad line: {line!r} -> {e.msg}')\n        return False","typeGuard":"def is_valid_requirement_line(line: str) -> bool:\n    return validate_line(line)","tryCatchPattern":"from pip._internal.req.req_file import get_line_parser, OptionParsingError\nfor line in open('requirements.txt'):\n    line = line.strip()\n    if not line or line.startswith('#'):\n        continue\n    try:\n        get_line_parser(None)(line)\n    except OptionParsingError as e:\n        print(f'fix line: {line} ({e.msg})'); raise SystemExit(1)","preventionTips":["Use pip's own parser to lint requirements files in CI.","Cross-check option names against 'pip install --help'.","Prefer '--opt=value' to avoid optparse ambiguities."],"tags":["requirements-file","parsing","config"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}