Conda 文件清理 - 删除未使用的包和缓存

Conda 文件清理 - 删除未使用的包和缓存

Command reference
https://conda.io/projects/conda/en/latest/commands.html

Remove unused packages and caches.
conda/pkgs 文件清理,删除未使用的包和缓存。

1. conda --help

(base) yongqiang@yongqiang:~$ conda --help
usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    clean        Remove unused packages and caches.
    config       Modify configuration values in .condarc. This is modeled
                 after the git config command. Writes to the user .condarc
                 file (/home/yongqiang/.condarc) by default.
    create       Create a new conda environment from a list of specified
                 packages.
    help         Displays a list of available conda commands and their help
                 strings.
    info         Display information about current conda install.
    init         Initialize conda for shell interaction. [Experimental]
    install      Installs a list of packages into a specified conda
                 environment.
    list         List linked packages in a conda environment.
    package      Low-level conda package utility. (EXPERIMENTAL)
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove.
    run          Run an executable in a conda environment. [Experimental]
    search       Search for packages and display associated information. The
                 input is a MatchSpec, a query language for conda packages.
                 See examples below.
    update       Updates conda packages to the latest compatible version.
    upgrade      Alias for conda update.

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit.

conda commands available from other packages:
  env
(base) yongqiang@yongqiang:~$

2. conda clean --help

(base) yongqiang@yongqiang:~$ conda clean --help
usage: conda 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
(base) yongqiang@yongqiang:~$

3. conda clean --all

(base) yongqiang@yongqiang:~$ conda clean --all
Cache location:
There are no tarballs to remove
WARNING: /home/yongqiang/.conda/pkgs does not exist
Cache location:
There are no unused packages to remove
(base) yongqiang@yongqiang:~$

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

在Linux上清理Conda(Python的一个包管理器)缓存,可以提高磁盘空间并保持环境整洁。以下是一些步骤: 1. **打开终端**:在Linux环境中,你可以通过快捷键Ctrl+Alt+T或者搜索“Terminal”打开终端。 2. **激活你的Conda环境**:如果要在特定环境下操作,首先需要激活它。例如,如果你的环境名为`myenv`,输入: ``` conda activate myenv ``` 3. **查找缓存路径**:Conda缓存通常存储在`~/.cache/conda`目录下,这里`~`代表用户主目录。你也可以使用`conda info --root`命令查看根目录。 4. **清理缓存**:在`~/.cache/conda`下,有`pkgs`和`conda-meta`两个重要子目录存放缓存文件。可以分别尝试删除它们,但注意这可能会永久丢失安装包的信息: - 清理`pkgs`: ``` rm -rf ~/.cache/conda/pkgs/* ``` - 清理`conda-meta`: ``` rm -rf ~/.cache/conda/conda-meta/* ``` 5. **确认清理**:清理完成后,检查磁盘空间是否有变化。如果不放心,可以在删除前备份这些文件。 6. **更新索引**:清理后,为了继续正常使用Conda,需要更新索引: ``` conda update conda conda index --clear conda install --force-reinstall anaconda-client ``` 7. **注意**: 对于频繁使用的开发环境,直接删除整个缓存可能不是最佳实践,因为每次安装都可能重新生成部分文件。若想定期清理,可以考虑设置自动缓存清除策略或者只删除过期或不再需要的包。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值