pypa/pip · error · CommandError

Too many arguments

Error message

Too many arguments

What it means

Raised by 'pip cache dir' (CacheCommand.get_cache_dir) when extra positional arguments are passed. The dir subcommand only prints the cache directory path and accepts zero arguments; any trailing token is rejected with CommandError 'Too many arguments'.

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 d7d0d0a394)

Solutions

  1. Drop the extra argument: 'pip cache dir' prints the current cache directory.
  2. To change the cache location, use 'pip install --cache-dir <path> ...' or set PIP_CACHE_DIR.
  3. If you wanted cache details, use 'pip cache info' instead.

Example fix

// before
pip cache dir /tmp/mypycache
// after
PIP_CACHE_DIR=/tmp/mypycache pip cache dir
Defensive patterns

Strategy: validation

Validate before calling

if extra_args:
    raise SystemExit("'pip cache dir' takes no arguments; use --cache-dir or PIP_CACHE_DIR to change location")

Prevention

When it happens

Trigger: Running 'pip cache dir something' or 'pip cache dir /custom/path' - users mistakenly trying to set or query a specific cache path through the dir subcommand.

Common situations: Assuming 'pip cache dir <path>' sets the cache location (it does not - use --cache-dir or PIP_CACHE_DIR); autocomplete inserting a stray argument; chaining subcommands like 'pip cache dir info'.

Related errors


AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04). Data as JSON: /data/errors/7b15fdf2ab57dc6d.json. Report an issue: GitHub.