Search code examples
pythoncondaenvironment

Set the channel_priority in Conda environment.yaml


Is it possible to set the channel_priority to strict when creating an environment using the yaml file? For example:

name: my_environment
channels:
  - conda-forge
dependencies:
  - python
  - geopandas
  - rasterio

Solution

  • One additional note is that a specified channel for a given package does not need to be listed in the channels section. I find this safer as it does not risk to (re-)install some other package from unexpected channel.

    So, for example:

    channels:
      - defaults
    
    dependencies:
      - python =3.8
      - ...
      # specifically from conda-forge (but only those):
      - conda-forge::nbsphinx
    

    Instead of:

    # NO!
    channels:
      - defaults
      - conda-forge
    
    dependencies:
      - python =3.8
      - ...
      - conda-forge::nbsphinx
    

    Importantly, this seems to install only the specified packages from conda-forge, and it doesn't try to (re-)install conda-forge versions of packages that are in the dependency graph of those, but are already available (perhaps with a slightly less cutting-edge version) from pkgs/main.