Last updated: Apr 10, 2024
Reading timeยท3 min
--no-cache-dir
optionThe --no-cache-dir
option is used to disable the cache.
pip install requests --no-cache-dir pip3 install requests --no-cache-dir
Pip caches:
HTTP responses - pip
first checks its local cache to determine if it has a
suitable response stored locally that hasn't expired. If the condition is met,
the local response is reused
locally built wheels - pip
attempts to use wheels from its local wheel cache
instead of rebuilding the project
The main purposes of pip's --no-cache-dir
option are:
pip
as root
. The installed
packages and the cached files are owned by root
and not accessible by other
users.Using the --no-cache-dir option disables pip's cache.
pip install requests --no-cache-dir pip3 install requests --no-cache-dir
You can use the pip cache dir
command to get the directory where pip's cache
is stored on your machine.
pip cache dir
The location is likely going to be the following.
# ๐๏ธ On Linux ~/.cache/pip # ๐๏ธ On macOS ~/Library/Caches/pip # ๐๏ธ On Windows %LocalAppData%\pip\Cache
You can use the pip cache info
command to get an overview of the contents of
pip's cache.
pip cache info
The pip cache info
command shows the total size of the cache and the location
where the HTTP responses and the locally built wheel
files are stored.
If you need to remove all wheel files related to a single package from the
cache, use the pip cache remove <package>
command.
pip cache remove requests
If you want to clear all wheel files from pip's cache, you would use the pip cache purge command.
pip cache purge
If you need to list all wheel files from pip's cache, you would use the
pip cache list
and pip cache list <package>
commands.
# ๐๏ธ List all wheel files from pip's cache pip cache list # ๐๏ธ List all wheel files related to requests from pip's cache pip cache list requests
As previously mentioned, the way to disable pip's default behavior of caching
HTTP responses and wheels is to use the --no-cache-dir
option after the
command.
pip install requests --no-cache-dir pip3 install requests --no-cache-dir
You will mostly see the option used when using Docker to reduce the size of images.
If you need to force a reinstall of a specific package, you can use either of the following options.
pip install requests --no-cache-dir pip install requests --ignore-installed pip install requests --force-reinstall
The --ignore-installed
option ignores the installed packages and overwrites
them.
The --force-reinstall option reinstalls all packages even if they are up-to-date.