Anaconda导出环境文件 [英] Anaconda export Environment file
问题描述
我如何制作可以在其他计算机上使用的anaconda环境文件?
How can I make anaconda environment file which could be use on other computers?
我使用conda env export > environment.yml
将anaconda python环境导出到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.
这篇关于Anaconda导出环境文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!