Anaconda 导出环境文件
问题描述
如何制作可以在其他电脑上使用的anaconda环境文件?
How can I make anaconda environment file which could be use on other computers?
我使用 conda env export > 将我的 anaconda python 环境导出到 YMLenvironment.yml
.导出的 environment.yml
包含这一行 prefix:/home/superdev/miniconda3/envs/juicyenv
映射到我的 anaconda 的位置,这在其他电脑上会有所不同.
I exported my anaconda python environment to YML using conda env export > environment.yml
. The exported environment.yml
contains this line prefix: /home/superdev/miniconda3/envs/juicyenv
which maps to my anaconda's location which will be different on other's pcs.
解决方案
我在 conda
规范中找不到任何允许您在没有 prefix: 的情况下导出环境文件的内容...
行.但是,正如 Alex 在评论中指出,conda 似乎没有从文件创建环境时关心前缀行.
I can't find anything in the conda
specs which allow you to export an environment file without the prefix: ...
line. However, as Alex pointed out in the comments, conda doesn't seem to care about the prefix line when creating an environment from file.
考虑到这一点,如果您希望其他用户不知道您的默认安装路径,您可以在写入 environment.yml之前使用
grep
删除前缀行代码>.
With that in mind, if you want the other user to have no knowledge of your default install path, you can remove the prefix line with grep
before writing to environment.yml
.
conda env export | grep -v "^prefix: " > environment.yml
无论哪种方式,其他用户都会运行:
Either way, the other user then runs:
conda env create -f environment.yml
并且该环境将安装在其默认的 conda 环境路径中.
and the environment will get installed in their default conda environment path.
如果你想为你的系统指定一个与默认安装路径不同的安装路径(与 environment.yml 中的 'prefix' 无关),只需使用 -p
标志,后跟所需的路径.
If you want to specify a different install path than the default for your system (not related to 'prefix' in the environment.yml), just use the -p
flag followed by the required path.
conda env create -f environment.yml -p /home/user/anaconda3/envs/env_name
请注意,Conda 建议手动创建 environment.yml
,如果您希望跨平台(Windows/Linux/Mac)共享您的环境,这一点尤其重要.在这种情况下,您可以省略 prefix
行.
Note that Conda recommends creating the environment.yml
by hand, which is especially important if you are wanting to share your environment across platforms (Windows/Linux/Mac). In this case, you can just leave out the prefix
line.
相关文章