Clearing the uv or pip cache can free disk space and help resolve problems caused by stale or corrupted package downloads. The right command depends on which installer you use and whether you want to remove one package’s cached files or everything. This guide explains how to inspect, clear, and maintain both caches on macOS, Linux, and Windows, while avoiding the common mistake of deleting your project’s virtual environment.
uv and pip have separate caches. Clearing one does not automatically clear the other. In most cases, use the installer’s own cache command rather than deleting files by hand.
What Does a Python Package Cache Do?
A package manager cache stores files used during installation, such as downloaded package archives, built wheels, and metadata. When you install a package again, the installer may reuse those files instead of downloading or building everything from scratch. This can make repeat installations faster and reduce network use.
A cache is separate from the packages installed in your Python environment. Removing cached files typically does not uninstall packages from a virtual environment or system Python. However, the next installation may take longer because the package manager has to download or rebuild files again.
Cache cleanup is useful when disk space is limited, a cached download appears damaged, or you need to check whether a fresh download fixes an installation issue. It is not usually necessary as routine maintenance: package caches are designed to be reused, and deleting them can slow down future installs.
How to Check the uv Cache
Before clearing anything, find out where uv stores its cache. Run:
uv cache dir
The command prints the active cache directory. Its location can vary by operating system and configuration. If you have set the UV_CACHE_DIR environment variable, uv uses that configured location instead of its default.
Checking the directory is especially helpful if a cleanup command does not appear to free space. You may be looking at a different cache directory from the one used by your current shell, user account, or automated build process.
How to Clear the Entire uv Cache
To remove all cached data managed by uv, run:
uv cache clean
This is the most direct answer to “How do I clear the uv cache?” The command removes the contents of uv’s cache. It does not normally remove packages already installed in a project’s virtual environment. The next time you install or sync dependencies, uv may need to fetch packages again or rebuild them.
Close or pause other package-installation tasks before cleaning the cache. If another process is using cached files, wait for it to finish and then run the command again if needed. You generally do not need administrator privileges when clearing a cache owned by your user account.
How to Clear One Package from the uv Cache
If you only want to remove cached data associated with a particular package, provide its name:
uv cache clean requests
Replace requests with the package you want to clean. This is more targeted than clearing the entire cache and can be useful when you suspect a specific cached package file is causing trouble. Package names that contain hyphens or other punctuation should be entered as the package is named on the package index.
After cleaning a package’s cache, rerun your normal uv installation or sync command. The package manager will obtain the files it needs again. Keep in mind that cleaning cached data is not the same as removing the package from your project’s dependency list or uninstalling it from an environment.
How to Prune the uv Cache
For routine cleanup, consider pruning rather than removing every cached file:
uv cache prune
Pruning removes cache data that uv considers unnecessary while retaining data it can still use. It is a useful option when you want to reduce cache storage without performing a complete reset. If you specifically need to discard all cached data, use uv cache clean instead.
For a build server or a computer with limited storage, pruning can be part of a maintenance routine. On a developer workstation, there is usually no need to run it after every installation. The cache exists to save time, so keep it unless you need the space or are troubleshooting.
How to Check the pip Cache
To see where pip stores cached files, run:
python -m pip cache dir
Using python -m pip helps ensure that the command runs with the Python interpreter you intend to use. If your system uses the python3 command, use:
python3 -m pip cache dir
You can also inspect the cache size and contents with these commands:
python -m pip cache info
python -m pip cache list
cache info reports information about cache storage, while cache list displays cached wheel files. The list may not show every item pip caches, so it should not be treated as a complete view of all cached HTTP responses.
How to Clear the Entire pip Cache
To remove all cached files managed by pip, run:
python -m pip cache purge
On systems where you use python3, run python3 -m pip cache purge. The purge command clears pip’s cache, including cached package downloads and wheels. It does not uninstall packages from your active environment or remove your project files.
After a purge, installing a package may take longer because pip has to download it again. If you are clearing the cache to troubleshoot an installation, retry the original install command after the purge. For example:
python -m pip install requests
If the install still fails, the cause may be a network problem, an incompatible Python version, a dependency conflict, or an issue with the package itself rather than the cache.
How to Remove a Specific Package from the pip Cache
To remove cached wheel files matching one package name, use pip cache remove:
python -m pip cache remove requests
Replace requests with the package you want to target. This command is useful when you want to avoid a full cache purge. Note that removing a package’s cached wheel files is not the same as uninstalling the package, and it may not remove every cached HTTP response related to that package.
To uninstall a package from the current Python environment, use pip’s uninstall command instead:
python -m pip uninstall requests
That distinction matters: pip cache remove affects cached files, while pip uninstall affects an installed package. Choose the command based on what you actually want to remove.
Clearing uv and pip Caches on Windows
The same cache commands work in PowerShell or Command Prompt, as long as the relevant executable is available. For uv, run:
uv cache dir
uv cache clean
uv cache prune
For pip, run:
py -m pip cache dir
py -m pip cache purge
The Windows py launcher can select a Python installation. If you use a particular version, you can specify it, for example, py -3.12 -m pip cache purge. Alternatively, use the Python executable associated with your virtual environment. This avoids accidentally running pip under a different Python installation.
If Windows reports that a command is not recognized, check that uv or Python is installed and available on your PATH. You can also run commands using the full path to the appropriate executable. Avoid deleting a folder just because its name contains “pip” or “uv”; first confirm the active cache location with the relevant cache dir command.
Can I Delete the Cache Folder Manually?
It is usually safer to use uv cache clean, uv cache prune, or python -m pip cache purge than to remove cache folders manually. The built-in commands know how the tools manage their cache and help reduce the risk of deleting the wrong files.
If you must remove a cache folder manually, first identify the exact active location with uv cache dir or python -m pip cache dir. Stop package installation processes, confirm that the folder belongs to the cache you intend to clear, and delete only that folder. Do not remove a project directory or virtual environment as a substitute for clearing the cache.
uv Cache vs. pip Cache: Which One Should You Clear?
Clear the cache belonging to the tool that performed the installation. If you installed dependencies with uv, use a uv cache command. If you installed them with pip, use pip cache. A project can use both tools at different times, so clearing one cache may not affect files stored by the other.
If you are unsure which installer is involved, check the command used in your project’s setup instructions, scripts, or CI configuration. You can also inspect the cache directories for both tools. There is generally no benefit to clearing both caches unless you have a specific reason, such as reclaiming disk space from both.
Common Cache-Clearing Mistakes to Avoid
- Confusing the cache with an environment: Clearing cached downloads does not remove installed packages. Deleting a virtual environment does remove its installed packages.
- Expecting faster installs after a purge: A cleared cache often makes the next installation slower because files must be downloaded or built again.
-
Using the wrong Python interpreter: Prefer
python -m pip,python3 -m pip, or the Windowspy -m piplauncher that matches your environment. -
Assuming one tool clears the other: The
uvand pip caches are separate. Run the appropriate command for each tool you use. - Using cache cleanup to fix every install error: Cache cleanup may help with stale or damaged cached files, but it will not resolve all dependency, network, or compatibility problems.
Quick Command Reference
- Show the uv cache location:
uv cache dir - Clear all uv cache data:
uv cache clean - Clear one package from the uv cache:
uv cache clean PACKAGE - Prune the uv cache:
uv cache prune - Show the pip cache location:
python -m pip cache dir - Inspect pip cache information:
python -m pip cache info - Remove one package’s cached wheels:
python -m pip cache remove PACKAGE - Clear the entire pip cache:
python -m pip cache purge
Conclusion
To clear the uv cache, use uv cache clean; to remove only one package’s cached data, add its package name, or use uv cache prune for routine cleanup. To clear the pip cache, run python -m pip cache purge, or use python -m pip cache remove PACKAGE to target cached wheels for one package.
Always check the active cache directory first if you are unsure which files will be affected. Remember that cache cleanup does not normally uninstall packages from your Python environment, but it can make future installations slower. Use the package manager’s own commands, clear only what you need, and keep your virtual environment separate from your cache.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.