问题:点缓存文件夹在哪里

Python pip缓存文件夹在哪里?我在安装过程中出错,现在使用缓存文件重新安装软件包

该目录在哪里?我想备份它们以便将来安装。可能吗 ?

例如我有一个:

Using cached cssselect-0.9.1.tar.gz

我在google中搜索了此目录,但是我看到的所有内容都是从文件夹中了解如何安装,我想找到默认的缓存目录。

还有一个问题,这些缓存文件将保留在该目录中还是将很快删除?

Where is Python pip cache folder? I had error during install and now reinstall packages using cache files

Where is that directory? I want 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 learn to how 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 ?


回答 0

这取决于操作系统。

对于pip 20.1或更高版本,您可以通过以下方式找到它:

pip cache dir

例如,对于macOS:

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

文件:

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:


回答 1

缓存目录的默认位置取决于操作系统:

的Unix

〜/ .cache / pip,它尊重XDG_CACHE_HOME目录。

苹果系统

〜/库/缓存/点

视窗

<CSIDL_LOCAL_APPDATA> \ pip \ Cache

车轮缓存

pip将从pip缓存目录内的子目录轮读取并使用在那里找到的所有软件包。[片段]

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

可以通过命令行选项更改缓存目录的位置--cache-dir

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.


回答 2

Pythonic和跨平台方式:

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'))

在后台,它可以规范化路径,为奇异的和普通的操作系统和平台管理不同的位置,执行Windows注册表查找。

值得一提的是,如果安装了不同的Python版本2.x和3.x,它们确实共享相同的缓存位置。

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.


回答 3

您可以备份关联的滚轮,而不必尝试执行缓存文件夹的备份。

将版本0.9.1的csselect的滚轮下载到/tmp/wheelhouse

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

安装下载的车轮:

pip install /tmp/wheelhouse/cssselect-0.9.1-py2-none-any.whl

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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。