How to avoid Python pip cache filling up my home directory
The default pip cache directory
The Python package manager pip uses a cache to reduce
network access and to avoid having to rebuild packages that have
already been built. By default this cache resides in the user's home
directory in ~/.cache/pip
. You can check what is your current pip
cache directory with the command pip cache dir
. For example:
For example installing PyTorch will put around 3.7 GB of files into
the cache, this can easily fill up your home directory
quota. You can clean up your cache either by simply
deleting it with rm -rf ~/.cache/pip
or (more gently) by using the
command pip cache purge
:
Changing the pip cache directory
To avoid problems in the future it might be a good idea to store your
pip cache on the scratch file system instead. The pip cache can be set
with the --cache-dir
flag or, globally by setting the
PIP_CACHE_DIR
environment variable. For example (change the path to
something appropriate for your project and user):
You can now test that pip has picked up this change:
If you want to make this setting permanent for your user, you can add
the export-line to the .bashrc
file in your home directory.