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
yml file. Note that by convention Conda environment files are called environment. yml . As such if you use the conda env create sub-command without passing the --file option, then conda will expect to find a file called environment.
To set configuration options, edit the . condarc file directly or use the conda config --set command. For a complete list of conda config commands, see the command reference. The same list is available at the terminal or Anaconda Prompt by running conda config --help .
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
To directly answer your question, no I don't think it is possible to add channel_priority
to the environment file. Maybe raise this as a Conda issue (if it isn't there already ;).
Something else worth trying would be adding defaults
to the channel listing explicitly with lower priority like so...
name: my_environment
channels:
- conda-forge
- defaults
dependencies:
- python
- geopandas
- rasterio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With