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 by RequirementCommand.get_requirements() in req_command.py:400 when --requirements-from-script is specified more than once. PEP 723 inline script metadata can only come from a single script file; multiple scripts would create ambiguous dependency resolution, so pip enforces a limit of one.
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 d7d0d0a394)
Solutions
- Use only one --requirements-from-script per pip install invocation.
- Run separate pip install commands for each script.
- Merge dependencies from multiple scripts into a single requirements file or a single PEP 723 script.
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
def validate_single_script(scripts):
"""Ensure only one --requirements-from-script is given."""
if isinstance(scripts, list) and len(scripts) > 1:
raise ValueError('--requirements-from-script can only be given once')
return True Try / catch
from pip._internal.exceptions import CommandError
try:
# pip install --requirements-from-script ...
except CommandError as e:
if '--requirements-from-script' in str(e) and 'once' in str(e):
# split into separate pip invocations
Prevention
- Pass only one script per pip install command.
- If you need deps from multiple scripts, merge them into a single requirements file.
- Validate argument counts in wrapper scripts before calling pip.
When it happens
Trigger: Calling `pip install --requirements-from-script a.py --requirements-from-script b.py`. The check at req_command.py:399 verifies len(options.requirements_from_scripts) > 1.
Common situations: Build scripts or Makefiles that accumulate --requirements-from-script flags in a loop. Combining multiple PEP 723 scripts in one pip install call. Misunderstanding that only one script is supported.
Related errors
- Cannot use '--only-dependencies' in combination with {confli
- When restricting platform and interpreter constraints using
- Can not use any platform or abi specific options unless inst
- Platform and interpreter constraints using --python-version,
- --build-constraint cannot be used with --no-build-isolation.
AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04).
Data as JSON: /data/errors/5106e7f69f92d1db.json.
Report an issue: GitHub.