pypa/pip · error · CommandError
Too many arguments
Error message
Too many arguments
What it means
Raised as CommandError by CacheCommand.get_cache_dir (cache.py:89) when `pip cache dir` is given any positional arguments. The dir subcommand (lines 87-91) takes no arguments: it simply prints options.cache_dir. The `if args:` guard at line 88 rejects extra tokens. The broader CacheCommand.run (lines 61-85) routes args[0] as the action and passes the remainder to the handler, so any token after `dir` triggers this.
Solutions
- Run `pip cache dir` with no arguments to print the cache directory.
- To use a custom cache directory, set it via the global `--cache-dir <dir>` option before the subcommand.
Example fix
# before pip cache dir /tmp/mypipcache # after pip --cache-dir /tmp/mypipcache cache dir
Defensive patterns
Strategy: validation
Validate before calling
# Disallow extra positional args for `pip cache dir`.
def validate_cache_dir_args(extra_args):
if extra_args:
raise ValueError("'pip cache dir' takes no arguments; use --cache-dir <dir> globally to change location")
return True Prevention
- Run `pip cache dir` and `pip cache info` with zero positional arguments.
- Use the global `--cache-dir` option to point pip at a different cache root.
When it happens
Trigger: `pip cache dir extra`, `pip cache dir /some/path`.
Common situations: Assuming `pip cache dir <dir>` sets or inspects a specific cache directory (it does not); copy-pasting a command with a stray token.
Related errors
- --refresh-package option requires 1 argument.
- --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/7b15fdf2ab57dc6d.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_internal/commands/cache.py:89
"Need an action (%s) to perform.",
", ".join(sorted(handler_map)),
)
return ERROR
action = args[0]
# Error handling happens here, not in the action-handlers.
try:
handler_map[action](options, args[1:])
except PipError as e:
logger.error(e.args[0])
return ERROR
return SUCCESS
def get_cache_dir(self, options: Values, args: list[str]) -> None:
if args:
raise CommandError("Too many arguments")
logger.info(options.cache_dir)
def get_cache_info(self, options: Values, args: list[str]) -> None:
if args:
raise CommandError("Too many arguments")
num_http_files = len(self._find_http_files(options))
num_packages = len(self._find_wheels(options, "*"))
http_cache_location = self._cache_dir(options, "http-v2")
old_http_cache_location = self._cache_dir(options, "http")
wheels_cache_location = self._cache_dir(options, "wheels")
http_cache_size = filesystem.format_size(
filesystem.directory_size(http_cache_location)
+ filesystem.directory_size(old_http_cache_location)
)
wheels_cache_size = filesystem.format_directory_size(wheels_cache_location)View on GitHub (pinned to f399c37189)