pypa/pip · error · PipError
Got unexpected number of arguments, expected
Error message
Got unexpected number of arguments, expected {n}. (example: "{prog} config {example}") What it means
Raised by `pip config` subcommands when the number of positional arguments does not match the expected count. _get_n_args at configuration.py:256 checks `len(args) != n`; each subcommand calls it with its expected n (list=0, get=1, set=2, unset=1, debug=0). The message includes the prog name and an example invocation.
Solutions
- Match the argument count: `set` needs key+value (2), `get`/`unset` need key (1), `list`/`debug` need none (0).
- Read the example printed in the error message — it shows the exact expected form.
- Use `pip config --help` to confirm the subcommand signature.
Example fix
// before pip config set global.index-url // after pip config set global.index-url https://pypi.org/simple
Defensive patterns
Strategy: validation
Validate before calling
# Enforce per-subcommand arity before calling pip config
EXPECTED = {"list": 0, "get": 1, "set": 2, "unset": 1, "debug": 0}
def validate_config_args(subcmd, args):
if subcmd not in EXPECTED:
raise ValueError("unknown config subcommand: %s" % subcmd)
if len(args) != EXPECTED[subcmd]:
raise ValueError("%s expects %d arg(s), got %d" % (subcmd, EXPECTED[subcmd], len(args)))
return True
Prevention
- Memorize arity: list/debug=0, get/unset=1, set=2.
- Wrap pip config calls with an arity-checking helper.
When it happens
Trigger: e.g. `pip config set foo` (1 arg, expected 2), `pip config get a b` (2 args, expected 1), or `pip config list extra` (1 arg, expected 0). The mismatch trips configuration.py:258.
Common situations: User forgets the value for set, passes extra tokens to get/list/debug, or misremembers the subcommand arity.
Related errors
- Need exactly one file to operate upon (--user, --site…
- Can not combine '--user' and '--prefix' as they imply…
- Can not combine '--user' and '--target'
- Could not determine appropriate file.
- Could not determine editor to use.
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/4153db9dfb4eb41c.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_internal/commands/configuration.py:263
)
try:
subprocess.check_call(f'{editor} "{fname}"', shell=True)
except FileNotFoundError as e:
if not e.filename:
e.filename = editor
raise
except subprocess.CalledProcessError as e:
raise PipError(f"Editor Subprocess exited with exit code {e.returncode}")
def _get_n_args(self, args: list[str], example: str, n: int) -> Any:
"""Helper to make sure the command got the right number of arguments"""
if len(args) != n:
msg = (
f"Got unexpected number of arguments, expected {n}. "
f'(example: "{get_prog()} config {example}")'
)
raise PipError(msg)
if n == 1:
return args[0]
else:
return args
def _save_configuration(self) -> None:
# We successfully ran a modifying command. Need to save the
# configuration.
try:
self.configuration.save()
except Exception:
logger.exception(
"Unable to save configuration. Please report this as a bug."
)
raise PipError("Internal Error.")
def _determine_editor(self, options: Values) -> str:View on GitHub (pinned to f399c37189)