3

This is a follow up question for this answer. For a conda environment specification file environment.yml, if the variable that I am defining is PATH, for example, how can I prepend or append to it instead of just overwriting it? Is the following correct?

name: foo
channels:
  - defaults
dependencies:
  - python
variables:
  MY_VAR: something
  OTHER_VAR: ohhhhya
  PATH: /some/path:$PATH
scottlittle
  • 18,866
  • 8
  • 51
  • 70
  • Hello, I am interested if anyone has the answer. As of yesterday, I used: `MY_VAR: $(CONDA_PREFIX)` and it worked well, but I updated Conda and it doesn't work anymore. Now running Conda 4.14.0 – Cyril Fougeray Sep 21 '22 at 07:28
  • Another related question: https://stackoverflow.com/questions/69534089/how-to-access-predefined-environment-variables-in-conda-environment-yml – scottlittle Oct 03 '22 at 17:01

1 Answers1

1

It dependes on whether you are using windows or linux. A look at the source code of the environment init code reveals that conda itself simply executes bash (linux) or cmd.exe (win) calls:

linux:

yield from (f"export {envvar}='{value}'" for envvar, value in sorted(env_vars.items()))

windows:

yield from (f'@SET "{envvar}={value}"' for envvar, value in sorted(env_vars.items()))

So make sure that you are using the correct syntax for your variable. In case of linux, that would be

variables:
  MY_VAR: something
  OTHER_VAR: ohhhhya
  PATH: /some/path $PATH

AFAIK windows uses ; to delimit entries, so you would probably have to do this (untested):

variables:
  MY_VAR: something
  OTHER_VAR: ohhhhya
  PATH: /some/path;%PATH%
sonovice
  • 813
  • 2
  • 13
  • 27