参考网址:stackoverflow.com/questions/6…
由于要复现论文,我最近在配置anaconda的环境,虽然anaconda配置在了D盘,但是环境还是装在了C盘,导致了爆红,因此想要移动到D盘。搬运了stackoverflow的解答。成功释放30多个G的C盘存储!
Configure Environment and Package Default Locations 配置环境和包默认位置
I'd guess that, despite your efforts to put your environments on the large partition, there is still a default user-level package cache and that is filling up the home partition. At minimum, set up a new package cache and a default environments directory on the large partition:
我猜,尽管您努力将环境放在大分区上,但仍有一个默认的用户级包缓存,并且正在填满主分区。至少,在大分区上设置一个新的包缓存和一个默认环境目录:
# create a new pkgs_dirs (wherever, doesn't have to be hidden)
mkdir -p /big_partition/users/user/.conda/pkgs
# add it to Conda as your default
conda config --add pkgs_dirs /big_partition/users/user/.conda/pkgs
# create a new envs_dirs (again wherever)
mkdir -p /big_partition/users/user/.conda/envs
# add it to Conda as your default
conda config --add envs_dirs /big_partition/users/user/.conda/envs
在进行设置之后,可以用conda config --show的命令查看当前配置,检查一下否已经配置好。
Now you don't have to fuss around with using the --prefix flag any more - your named environments (conda create -n foo) will by default be created inside this directory and you can activate by name instead of directory (conda activate foo).
现在,您不必再大惊小怪地使用该 --prefix 标志 - 默认情况下,您的命名环境( )将在此目录中创建,您可以按名称而不是目录( conda create -n foo )激活 conda activate foo 。
Transferring Previous Environments and Package Cache
Unfortunately, there's not a great way to move Conda environments across filesystems without destroying the hardlinks. Instead, you'll need to recreate your environments. Since you may or may not want to bother with this, I'm only going to outline it. I can elaborate if needed.
不幸的是,没有一种好方法可以在不破坏硬链接的情况下跨文件系统移动 Conda 环境。相反,您需要重新创建环境。由于您可能想也可能不想为此烦恼,因此我仅概述一下。如果需要,我可以详细说明。
- Archive environments. Use
conda env export -n foo > foo.yaml(One per environment.) - Move package cache. Copy contents of old package cache (
/home/users/user_name/.conda/envs/.pkgs/) to new package cache. - Recreate environments. Use
conda env create -n foo -f foo.yaml.
Again, you could just skip this altogether. This is mainly if you want to be very thorough about transferring and not having to redownload stuff for environments you already created.
同样,您可以完全跳过此操作。这主要是如果您想非常彻底地传输并且不必为您已经创建的环境重新下载内容。
After this you can delete some the stuff under the old ~/.conda/envs/pkgs folder.
在此之后,您可以删除旧 ~/.conda/envs/pkgs 文件夹下的一些内容。
值得注意的是,新的./conda/envs不用迁移之前的内容,在重新创建的时候anaconda会重新安装的。