简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM