Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set environment variables in `environment.yml`

Can I set environment variables in environment.yml files in conda environments?

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?

like image 403
Dominik Stańczak Avatar asked Dec 08 '17 08:12

Dominik Stańczak


People also ask

Can you use environment variables in Yaml file?

Environment variables can be used in the following file types: Markdown and MDX. YAML, including portal configuration files. JavaScript and TypeScript, including the theme.

How do you set environment variables?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.

How use variable in Yaml?

YAML does not natively support variable placeholders. Anchors and Aliases almost provide the desired functionality, but these do not work as variable placeholders that can be inserted into arbitrary regions throughout the YAML text. They must be placed as separate YAML nodes.


1 Answers

It looks like this was added in Conda v4.9!

There is documentation at https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#setting-environment-variables

Environment variables set using conda env config vars will be retained in the output of conda env export. Further, you can declare environment variables in the environment.yml file as shown here:

name: env-name
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.7
  - codecov
variables:
  VAR1: valueA
  VAR2: valueB

Older versions of conda will complain;

EnvironmentSectionNotValid: The following section on 'environment.yml' is invalid and will be ignored:
 - variables        
like image 149
Tim 'mithro' Ansell Avatar answered Oct 29 '22 18:10

Tim 'mithro' Ansell