Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conda: set environment specific channels in environment.yml

If I specify channels: in my env.yml file, the packages used for the env creation are indeed from this channel.

$ cat env.yml 
channels:
  - conda-forge
  - nodefaults
dependencies:
  - python=3.8
  - numpy

Create env:

$ conda env create -n test -f env.yml
$ conda activate test

The packages are installed though the correct channel:

$ conda list 
# packages in environment at /home/mathurin/anaconda3/envs/test:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge

But when, inside this env, I later install other packages, they are still from the defaults channels:

$ conda config --show channels 
channels:
  - defaults

How can I tell conda to set, once and for all, the channels to something for this env, and can it be done inside the environement.yml ?

like image 892
P. Camilleri Avatar asked Sep 17 '25 17:09

P. Camilleri


1 Answers

This isn't possible through a YAML. However, one can set environment-specific configuration settings.

conda activate test
conda config --env --append channels conda-forge --append channels nodefaults

The key this is the --env argument: This edits a .condarc in the envs/test/ directory, which will take precedence over any system- or user-level .condarc. However, both .condarc files will be loaded, so if you explicitly have defaults in your ~/.condarc, it will still show up after the environment-specific ones.

like image 159
merv Avatar answered Sep 20 '25 06:09

merv