Where is pip cache folder?
Question:
Where is the Python pip cache folder? I had an error during installation and now reinstall packages using cache files. Where is that directory? I want to take a backup of them for installation 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 nothing I saw, is learning how to install from a folder, I want to find the default cache directory.
And another question: Will these cache files stay in that directory, or will they be removed soon?
Answers:
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
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>pipCache
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
.
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.
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:
Where is the Python pip cache folder? I had an error during installation and now reinstall packages using cache files. Where is that directory? I want to take a backup of them for installation 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 nothing I saw, is learning how to install from a folder, I want to find the default cache directory.
And another question: Will these cache files stay in that directory, or will they be removed soon?
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
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>pipCache
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
.
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.
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: