pypa/pip · error · CommandError
--requirements-from-script can only be given once
Error message
--requirements-from-script can only be given once
What it means
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.
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.
Example fix
# before pip install --requirements-from-script a.py --requirements-from-script b.py # after pip install --requirements-from-script a.py pip install --requirements-from-script b.py
Defensive patterns
Strategy: validation
Validate before calling
# Allow at most one --requirements-from-script.
def validate_scripts(scripts):
if len(scripts) > 1:
raise ValueError("--requirements-from-script can only be given once; install scripts one at a time")
return True Prevention
- Loop over scripts and invoke pip once per script instead of passing the flag repeatedly.
When it happens
Trigger: `pip install --requirements-from-script a.py --requirements-from-script b.py`.
Common situations: Scripting a workflow that installs deps from multiple PEP 723 scripts and assuming the flag is repeatable; merging two install commands naively.
Related errors
- Script requires a different Python: not in
- --build-constraint cannot be used with --no-build-isolation.
- Can not use any platform or abi specific options unless…
- Cannot combine '--path' with '--user' or '--local'
- Cannot use '--only-dependencies' in combination with
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/5106e7f69f92d1db.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_internal/cli/req_command.py:400
continue
for parsed_req in parse_requirements(
filename, finder=finder, options=options, session=session
):
req_to_add = install_req_from_parsed_requirement(
parsed_req,
isolated=options.isolated_mode,
user_supplied=True,
config_settings=(
parsed_req.options.get("config_settings")
if parsed_req.options
else None
),
)
requirements.append(req_to_add)
if options.requirements_from_scripts:
if len(options.requirements_from_scripts) > 1:
raise CommandError("--requirements-from-script can only be given once")
script = options.requirements_from_scripts[0]
try:
script_metadata = pep723_metadata(script)
except PEP723Exception as exc:
raise CommandError(exc.msg)
script_requires_python = script_metadata.get("requires-python", "")
if script_requires_python and not options.ignore_requires_python:
target_python = make_target_python(options)
if not check_requires_python(
requires_python=script_requires_python,
version_info=target_python.py_version_info,
):
raise UnsupportedPythonVersion(
f"Script {script!r} requires a different Python: "View on GitHub (pinned to f399c37189)