问题描述
我可以在 conda 环境中的environment.yml
文件中设置环境变量吗?
Can I set environment variables in environment.yml
files in conda environments?
Conda让我在环境中保存环境变量通过env_vars.sh
脚本,但是有一种方法可以根据environment.yml
中某些环境变量的规范自动在activate.d
,deactivate.d
目录中创建env_vars.sh
文件.具有MKL_THREADING_LAYER=GNU
?
Conda lets me save environment variables in environments via the env_vars.sh
script, but is there a way to automate the process of creating env_vars.sh
files in the activate.d
, deactivate.d
directories according to some specification of environment variables within environment.yml
, for a reproducible environment with, say, MKL_THREADING_LAYER=GNU
?
推荐答案
当前状态(Conda v4.7.12)
否,无法在env YAML中设置特定于env的环境变量.
Current Status (Conda v4.7.12)
No, it is not possible to set env-specific environment variables in an env YAML.
正如@Ben在评论中指出的那样,这是一个开放功能请求 .尽管从技术上讲它没有设置里程碑,但引用此问题的拉取请求是作为里程碑Conda v4.8.0的一部分进行了合并,看起来好像它为env特定的环境变量(即,无需手动编写激活钩子)提供了一些基础结构.例如,PR添加了一个conda-env
命令vars
,该命令可以像
As @Ben pointed out in comments, this has been an open feature request. While it technically doesn't have a milestone set, a pull request referencing this issue was merged as part of milestone Conda v4.8.0 that looks like it provides some infrastructure for env-specific environment variables (i.e., without manually writing activation hooks). For example, the PR adds a conda-env
command vars
that can be used like
conda env vars set MKL_THREADING_LAYER=GNU
但是,我找不到用于从YAML解析vars的代码,也找不到用于将vars导出至YAML的新代码(但是,我只能略过它-主要是查看添加的测试).
However, I could find neither code for parsing vars from a YAML nor new code for exporting vars to a YAML (but, admittedly, I only skimmed through it - mainly looking at the tests that were added).
总而言之,最终答案仍然尚未,但是可能很快就会出现.
In summary, the final answer is still not yet, but it could be on the horizon.
这篇关于在`environment.yml`中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!