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

  1. Install from one script at a time: run `pip install --requirements-from-script a.py` then `pip install --requirements-from-script b.py`.
  2. 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

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


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)