目录

  • 序言
  • 磁盘空间可视化软件SpaceSniffer
  • 删除pip缓存
  • 清理conda缓存
  • 最后


序言

当我们在肝了很多项目之后,往往会发现C盘爆红,可上网搜寻C盘清理攻略时却发现都是很寻常很普遍的方法。跟着教程清理一遍后并没有什么效果,而自己找到一些大文件后也不清楚该不该清理。为了解决这些问题,这篇博文应运而生。

磁盘空间可视化软件SpaceSniffer

Windows python 清除cpu缓存 python清除缓存的命令_缓存


SpaceSniffer是由Uderzo公司研发的一款磁盘空间分析软件,安装包体积很小。对于我们有针对的解决C盘里的大文件很有帮助。

通过这个软件我们往往会发现C盘里AppData这个文件夹吃掉了我们相当多的内存。

官网链接

删除pip缓存

在使用pip安装Python包时,pip会将下载的包缓存到本地,方便下次可以快速获取。这里我大概清理出了20g。
一、找到pip缓存的目录
在命令行输入:

pip cache dir

这时终端会输出pip缓存的路径。

// 路径往往是这样的
c:\users\用户名\appdata\local\pip\cache

二、删除缓存文件
我们可以手动删除缓存文件,也可以使用命令删除。

pip cache purge

清理conda缓存

在我们使用conda一段时间后,它也会在其pkgs路径下存放许多缓存的包,我们同样需要进行清理。这里我清理出了大概20g。

// 路径往往是这样的
C:\Users\用户名\AppData\Local\conda\conda\pkgs

这里我们同样可以使用终端进行删除。如果把握不准我们可以看下提示,输入:

conda clean -h

我们可以看到各种提示:

usage: conda-script.py clean [-h] [-a] [-i] [-p] [-t] [-f] [-c TEMPFILES [TEMPFILES ...]] [-d] [--json] [-q] [-v] [-y]

Remove unused packages and caches.

Options:

optional arguments:
  -h, --help            Show this help message and exit.

Removal Targets:
  -a, --all             Remove index cache, lock files, unused cache packages, and tarballs.
  -i, --index-cache     Remove index cache.
  -p, --packages        Remove unused packages from writable package caches. WARNING: This does not check for packages
                        installed using symlinks back to the package cache.
  -t, --tarballs        Remove cached package tarballs.
  -f, --force-pkgs-dirs
                        Remove *all* writable package caches. This option is not included with the --all flag.
                        WARNING: This will break environments with packages installed using symlinks back to the
                        package cache.
  -c TEMPFILES [TEMPFILES ...], --tempfiles TEMPFILES [TEMPFILES ...]
                        Remove temporary files that could not be deleted earlier due to being in-use. Argument is
                        path(s) to prefix(es) where files should be found and removed.

Output, Prompt, and Flow Control Options:
  -d, --dry-run         Only display what would have been done.
  --json                Report all output as json. Suitable for using conda programmatically.
  -q, --quiet           Do not display progress bar.
  -v, --verbose         Can be used multiple times. Once for INFO, twice for DEBUG, three times for TRACE.
  -y, --yes             Do not ask for confirmation.

Examples:

    conda clean --tarballs

这里我推荐使用

conda clean -t

它会清除缓存下来的压缩文件。其他的如 -p 大家如果需要也可以试试。