{"record":{"id":"5106e7f69f92d1db","repo":"pypa/pip","slug":"requirements-from-script-can-only-be-given-once","errorCode":null,"errorMessage":"--requirements-from-script can only be given once","messagePattern":"--requirements-from-script can only be given once","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/cli/req_command.py","lineNumber":400,"sourceCode":"                continue\n            for parsed_req in parse_requirements(\n                filename, finder=finder, options=options, session=session\n            ):\n                req_to_add = install_req_from_parsed_requirement(\n                    parsed_req,\n                    isolated=options.isolated_mode,\n                    user_supplied=True,\n                    config_settings=(\n                        parsed_req.options.get(\"config_settings\")\n                        if parsed_req.options\n                        else None\n                    ),\n                )\n                requirements.append(req_to_add)\n\n        if options.requirements_from_scripts:\n            if len(options.requirements_from_scripts) > 1:\n                raise CommandError(\"--requirements-from-script can only be given once\")\n\n            script = options.requirements_from_scripts[0]\n            try:\n                script_metadata = pep723_metadata(script)\n            except PEP723Exception as exc:\n                raise CommandError(exc.msg)\n\n            script_requires_python = script_metadata.get(\"requires-python\", \"\")\n\n            if script_requires_python and not options.ignore_requires_python:\n                target_python = make_target_python(options)\n\n                if not check_requires_python(\n                    requires_python=script_requires_python,\n                    version_info=target_python.py_version_info,\n                ):\n                    raise UnsupportedPythonVersion(\n                        f\"Script {script!r} requires a different Python: \"","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/cli/req_command.py#L382-L418","documentation":"Raised as CommandError in RequirementCommand.get_requirements (req_command.py:400) when --requirements-from-script is supplied more than once. The option is `append`-style, so pip collects all occurrences into options.requirements_from_scripts; the guard at line 399 checks len > 1 and rejects it because a single PEP 723 inline-script metadata block is expected to fully describe the requirements. Processing two scripts would create ambiguity about which script's requires-python and dependencies apply.","triggerScenarios":"`pip install --requirements-from-script a.py --requirements-from-script b.py`.","commonSituations":"Scripting a workflow that installs deps from multiple PEP 723 scripts and assuming the flag is repeatable; merging two install commands naively.","solutions":["Install from one script at a time: run `pip install --requirements-from-script a.py` then `pip install --requirements-from-script b.py`.","Merge the dependency metadata of both scripts into a single PEP 723 script if you want one install operation."],"exampleFix":"# before\npip install --requirements-from-script a.py --requirements-from-script b.py\n# after\npip install --requirements-from-script a.py\npip install --requirements-from-script b.py","handlingStrategy":"validation","validationCode":"# Allow at most one --requirements-from-script.\ndef validate_scripts(scripts):\n    if len(scripts) > 1:\n        raise ValueError(\"--requirements-from-script can only be given once; install scripts one at a time\")\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Loop over scripts and invoke pip once per script instead of passing the flag repeatedly."],"tags":["cli-options","requirements-from-script","pep723","command-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}