存储的 wheels .whl 缓存文件在哪里?

Where are stored wheels .whl cached files?

$ python3 -m venv ~/venvs/vtest
$ source ~/venvs/vtest/bin/activate
(vtest) $ pip install numpy
Collecting numpy
  Cache entry deserialization failed, entry ignored
  Using cached https://files.pythonhosted.org/packages/d2/ab/43e678759326f728de861edbef34b8e2ad1b1490505f20e0d1f0716c3bf4/numpy-1.17.4-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy
Successfully installed numpy-1.17.4
(vtest) $

我正在查找此轮子 numpy-1.17.4-cp36-cp36m-manylinux1_x86_64.whl 的缓存位置?

$ sudo updatedb
$ locate numpy-1.17.4
$ # nada ;(

文档 https://pip.pypa.io/en/stable/reference/pip_install/#wheel-cache 告诉我们 Pip will read from the subdirectory wheels within the pip cache directory and use any packages found there.

$ pip --version
pip 9.0.1 from ~/venvs/vtest/lib/python3.6/site-packages (python 3.6)
$

回答 Hamza Khurshid numpy 不在 ~/.cache/pip/wheels

$ find ~/.cache/pip/wheels -name '*.whl' |grep -i numpy
$

看起来 .cache/pip/wheels 仅用于用户创建的轮子而不用于下载的轮子,我应该使用 export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache 吗?

查找WHL缓存文件请参考以下路径

在windows,

%USERPROFILE%\AppData\Local\pip\cache

在 Unix 中,

~/.cache/pip

在 macOS 中,

~/Library/Caches/pip.

留言

Using cached https://files.pythonhosted.org/packages/d2/ab/43e678759326f728de861edbef34b8e2ad1b1490505f20e0d1f0716c3bf4/numpy-1.17.4-cp36-cp36m-manylinux1_x86_64.whl

意味着 pip 使用的是 HTTP 缓存,而不是 wheel 缓存(它只用于本地构建的 wheel,就像你提到的那样)。

HTTP 缓存中的文件名是被请求的 URL 的 sha224。

您可以像

一样检索文件
$ pwd
/home/user/.cache/pip/http
$ find . -name "$(printf 'https://files.pythonhosted.org/packages/65/26/32b8464df2a97e6dd1b656ed26b2c19460
6c16fe163c695a992b36c11cdf/six-1.13.0-py2.py3-none-any.whl' | sha224sum - | awk '{print }')"
./f/6/0/2/d/f602daffc1b0025a464d60b3e9f8b1f77a4538b550a46d67018978db

文件格式不稳定,取决于pip版本。具体可以看pip使用的最新cachecontrol中的实现。

如果你想得到实际的文件,一个更简单的方法是使用 pip download,如果它与 URL 匹配,它将把文件从缓存中取出到你的当前目录否则下载。