Python pip缓存文件夹在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34578168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:12:33  来源:igfitidea点击:

Where is pip cache folder

pythonpip

提问by Arash Hatami

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

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

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 ?

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

采纳答案by Hugo

It depends on the operating system.

这取决于操作系统。

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

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

pip cache dir

For example with macOS:

以 macOS 为例:

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

Docs:

文档:

回答by fredrik

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

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

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

将 0.9.1 版 csselect 的轮子下载到/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

回答by ptim

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

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

Unix

~/.cache/pip 并且它尊重 XDG_CACHE_HOME 目录。

苹果系统

〜/图书馆/缓存/点

视窗

<CSIDL_LOCAL_APPDATA>\pip\Cache

轮缓存

pip 将从 pip 缓存目录中的子目录轮子中读取并使用在那里找到的任何包。[剪辑]

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.

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

回答by Rabash

Pythonic and cross-platform way:

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

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

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

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.

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