Set the channel_priority in Conda environment.yaml

Thanks to merv.
A workaround is to specify the channel for each package:

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

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.


A straightforward way is to first create the empty environment and set the channel priority to strict, then install the packages from the spec file:

conda create new_env
conda activate new_env
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict
conda env update --name new_env --file env.yml 

Note: if using a .txt spec file instead of .yml then replace the last line with

conda install --name new_env --file env.txt

reference doc: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#id13