LinuxCommandLibrary

pip-cache

Manage pip's package cache

TLDR

Show the location of the pip cache directory

$ pip cache dir
copy

List filenames of all packages currently stored in the cache
$ pip cache list
copy

Remove all files from the pip cache
$ pip cache purge
copy

Remove cached files matching a specific package name
$ pip cache remove [package_name]
copy

SYNOPSIS

pip cache <command> [<options>]

PARAMETERS

dir
    Displays the path to pip's cache directory.

info
    Shows a summary of the cache usage, including its total size and the number of entries.

list [<options>]
    Lists the packages currently stored in the cache. Can be filtered or formatted using options.
Options:
--format : Specifies the output format (e.g., 'json', 'text').

purge
    Clears the entire pip cache, removing all stored packages and freeing up disk space.

remove <package_name> [<package_name> ...]
    Removes specific packages from the cache. Multiple package names can be provided to remove several at once.

DESCRIPTION

pip cache is a powerful subcommand of the pip package installer that allows users to manage its local cache of downloaded packages. This cache stores source distributions and wheel files for packages, significantly speeding up subsequent installations of the same packages or dependencies, especially in environments with limited internet access or for offline development.

It helps conserve bandwidth and reduces build times by avoiding repeated downloads. The pip cache command provides various subcommands to inspect, list, clear, or remove specific items from this cache, making package management more efficient.

CAVEATS

The cache can grow quite large over time, consuming significant disk space. Regular use of pip cache purge or pip cache remove might be necessary to manage its size.
Note that the cache stores downloaded distributions, not installed ones. Removing a package from the cache does not uninstall it from your Python environment.
Using the global option --no-cache-dir with pip install will bypass the cache entirely for that specific installation command.

CACHE LOCATION

The default cache directory for pip is typically ~/.cache/pip on Linux and macOS, and %LocalAppData%\pip\Cache on Windows. This location can be overridden using the PIP_CACHE_DIR environment variable or the --cache-dir global option with any pip command.

CACHE STRATEGY

When pip needs to install a package, it first checks if the required distribution (wheel or source archive) is already present in its cache. If found, it uses the cached version, avoiding a re-download. If not, it downloads the distribution and then caches it before proceeding with the installation. This intelligent caching mechanism significantly optimizes the installation workflow, especially for frequently used packages or when working offline.

HISTORY

The pip cache subcommand was introduced in pip version 10.0, which was released in May 2018. Prior to its introduction, managing pip's cache typically involved manually locating and deleting files from the cache directory (e.g., ~/.cache/pip on Linux/macOS). The pip cache command formalized and streamlined this management process, providing a consistent and user-friendly interface for cache interaction.

SEE ALSO

pip(1), pip install(1), pip download(1)

Copied to clipboard