Part of: Mac disk cleanup for developers: every cache, what it costs to rebuild (Developers)
Run pip cache dir to find the pip cache folder. It only holds downloads, so it is safe to clear: pip fetches packages again when you next install them. conda has a similar package cache, plus the environments themselves, which are the larger part.
pip is Python’s package installer. conda is a package and environment manager from the Anaconda world. They store different things in different places.
Find the pip cache
pip3 cache dir
pip3 cache info
The first prints the folder. On the Mac used to check this article it was ~/Library/Caches/pip. The second prints sizes: the cache of package index pages and the number of files. Both commands only read.
Use pip3 if pip is not found on your Mac, since some installs name it that way.
To see the size on disk:
du -sh "$(pip3 cache dir)"
On that Mac, the cache was under a hundred megabytes. It grows slowly, unless you install large scientific packages often.
Safe, risky, never
- Safe: the pip cache. Cost: re-download of packages on the next install. Pip’s own cache commands exist; see pip’s documentation for removing items from it.
- Risky: conda environments you still use, and the conda
pkgsfolder when environments link to it. Let conda clean its own package cache instead of deleting files by hand. - Never: do not delete a virtual environment’s
site-packagesor an Anacondaenvsfolder to “clear the cache”. That removes installed packages, not downloads. Also never delete the Python that your system or other tools use.
What conda keeps
Anaconda and Miniconda keep several things:
- Environments: each environment has a full set of installed packages. These are the largest part, and each environment costs a lot to recreate.
- A package cache, usually a
pkgsfolder inside the install. It holds downloaded archives and extracted copies, and environments link to the extracted copies.
If you have conda installed, check with du -sh on its folder. conda was not installed on the Mac used to check this article, so the exact paths and the command for cleaning its cache are not shown here. Conda’s documentation lists them for your version.
The key point: clearing the conda package cache is generally safe, because it only holds copies. Removing an environment is a bigger step, and it is worth listing your environments first and removing the ones you no longer use through conda itself.
What it costs
Clearing the pip cache costs a download per package the next time you install it. pip also caches wheels it built from source, which is slower to rebuild than to download, so large packages with native code take longer the second time. For conda, a cleared package cache costs downloads when you create new environments. Existing environments keep working, because they hold their own links or copies.
How to clear them
- Find the pip cache with the command above.
- Use pip’s own cache commands, or move the folder to the Trash in Finder and empty it. See why the Trash does not free space.
- For conda, use conda’s own cleaning options, from its documentation, and remove unused environments through conda, not by hand.
- Create or update an environment to check that installs still work.
Virtual environments are separate
A virtual environment is a folder inside a project, often called .venv or venv, that holds that project’s installed packages. These are not caches. Like node_modules, they can be recreated from a requirements file, if you have one. Check that you do before removing one. See the node_modules guide for the same idea.
For similar caches in other tools, see npm, Yarn and pnpm and the Go module cache. The wider list is in the developer cleanup guide.
Worked example: what pip says about itself
Two more read-only commands show how much pip keeps:
pip3 --version
pip3 cache list
On the Mac used to check this article, the first printed a pip version and the Python it belongs to, which was Homebrew’s Python under /opt/homebrew. The second printed “No locally built wheels cached.” That means pip had no locally built wheels stored. Note that pip cache list ignores the HTTP cache of downloaded files, so this output alone does not show what else the cache holds. Use du -sh on the cache folder for the full size.
The path in the first command is useful. A Mac can have several Pythons, such as the system one, Homebrew’s and one from a version manager. Run pip3 --version in the shell you use for work, so you know which pip you are asking.
Wheels and source builds
A wheel is a ready-to-install Python package file. Pip downloads wheels when it can. When it cannot, it builds from source and may keep the built wheel. A built wheel for a large package costs real compile time to recreate. That is the one cache item worth a second thought.
If something goes wrong
pip: command not found. Usepip3, or runpython3 -m pipinstead.- An install is slow after clearing. Pip is downloading again, and may be compiling.
- A package will not install and you suspect the cache. Check
pip3 help installfor an option that skips the cache for one install. - Your virtual environment stopped working. You deleted the wrong folder. A cache clear never touches
.venv.
When not to clean
Do not clear it just before you must install packages offline. Skip it entirely if the cache is small, as it was here.
See sizes in a scan
DiskJoy is our product. Its scan reads your disk and shows how large these folders are, read-only. Cleanup is not built yet, so DiskJoy does not remove them today.
Frequently asked questions
Where is the pip cache folder on a Mac?
Run pip cache dir. On the Mac used to check this article it printed a folder named pip inside the user Library Caches folder.
Is the pip cache safe to delete?
Yes. It only holds downloaded package files and web responses. pip downloads packages again when you install them. Packages already installed in your environments are not stored in the cache.
Why is Anaconda taking up so much space?
Anaconda installs a full set of scientific packages, and conda keeps downloaded package archives and old extracted copies in a package cache. Check the size of your Anaconda or Miniconda folder with du -sh.