Where is pip cache folder?

124,394

Solution 1

It depends on the operating system.

With pip 20.1 or later, you can find it with:

pip cache dir

For example with macOS:

$ pip cache dir
/Users/hugo/Library/Caches/pip

Docs:

Solution 2

The default location for the cache directory depends on the Operating System:

Unix

~/.cache/pip and it respects the XDG_CACHE_HOME directory.

macOS

~/Library/Caches/pip

Windows

<CSIDL_LOCAL_APPDATA>\pip\Cache

Wheel Cache

pip will read from the subdirectory wheels within the pip cache directory and use any packages found there. [snip]

https://pip.pypa.io/en/latest/reference/pip_install/#caching

The location of the cache directory can be changed via the command line option --cache-dir.

Solution 3

Pythonic and cross-platform way:

import pip
from distutils.version import LooseVersion
if LooseVersion(pip.__version__) < LooseVersion('10'):
    # older pip version
    from pip.utils.appdirs import user_cache_dir
else:
    # newer pip version
    from pip._internal.utils.appdirs import user_cache_dir
print(user_cache_dir('pip'))
print(user_cache_dir('wheel'))

Under the hood, it normalizes paths, manages different locations for exotic and ordinary operating systems and platforms, performs Windows registry lookup.

It may worth mentioning, if you have different Python versions installed, 2.x'es and 3.x'es, they all do share the same cache location.

Solution 4

You can backup the associated wheel rather than attempting to perform a backup of the cache folder.

Download the wheel for csselect of version 0.9.1 into /tmp/wheelhouse:

pip wheel --wheel-dir=/tmp/wheelhouse cssselect==0.9.1

Install the downloaded wheel:

pip install /tmp/wheelhouse/cssselect-0.9.1-py2-none-any.whl
Share:
124,394
Arash Hatami
Author by

Arash Hatami

Hi , I'm Arash A 27 years old self-taught DevOps & Backend developer from Iran

Updated on July 08, 2021

Comments

  • Arash Hatami
    Arash Hatami over 1 year

    Where is Python pip cache folder? I had an error during install and now reinstall packages using cache files. Where is that directory? I want to backup them for install in the future. Is it possible?

    For example, I have this one

    Using cached cssselect-0.9.1.tar.gz
    

    I searched google for this directory but anything I saw, is learning how to install from a folder, I want to find default cache directory. And another question, these cache files will stay in that directory or will remove soon?

  • Blaise
    Blaise about 5 years
    How stable/predictable is the cssselect-0.9.1-py2-none-any.whl file name?
  • fredrik
    fredrik about 5 years
    Depends on what the maintainers are doing in their setup.py when packaging.
  • Gringo Suave
    Gringo Suave over 4 years
    ModuleNotFoundError: No module named 'pip.utils' , pip 10.0.1 on Ubuntu.
  • Winand
    Winand over 3 years
    <CSIDL_LOCAL_APPDATA> == %LOCALAPPDATA%
  • ryanjdillon
    ryanjdillon over 3 years
    If you wanted pip's own cache directory you could also just use from pip._internal.locations import USER_CACHE_DIR or python -c "from pip._internal.locations import USER_CACHE_DIR; print(USER_CACHE_DIR)" if you were grabbing things in a script, etc.
  • Alex78191
    Alex78191 about 3 years
    %LOCALAPPDATA%\pip\Cache
  • bers
    bers about 3 years
    $XDG_CACHE_HOME is empty. find ~/.cache/pip | grep -i tensor shows tensorflow_determinism and silence_tensorflow wheels, but not tensorflow-gpu. Yet pip install tensorflow-gpu says Using cached https://.../tensorflow_gpu-2.0.0-cp37-cp37m-manylinux2010_x8‌​6_64.whl. Where else should I look for this file?
  • bers
    bers about 3 years
    (I also downloaded tensorflow_gpu-2.0.0-cp37-cp37m-manylinux2010_x86_64.whl and checked for duplicates using fdupes, but could not find any...)
  • Arash Hatami
    Arash Hatami over 2 years
    Yeah ... It's an old question ( about 4 years :D )
  • Hugo
    Hugo over 2 years
  • pradyunsg
    pradyunsg over 2 years
    Please do not go into _internal and fetch values. pip's internals are not meant to be used like a library and subject to change. pip cache dir on pip 20.1 and above is the best way to get this value.
  • Alex Povel about 2 years
    See also the PIP_CACHE_DIR environment variable to set this directory.
  • mrclary
    mrclary 8 months
    $ pip install --no-deps --force black Downloading black-22.3.0-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB) Successfully installed black-22.3.0 $ pip install --no-deps --force black Using cached black-22.3.0-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB) Successfully installed black-22.3.0 $ pip cache list Nothing cached.