Reputation: 20287
I'm running into a minor but annoying issue with conda when installing individual packages from conda-forge. Typically I'd run something like this:
conda install -c conda-forge somepackage
This has the effect of frequently updating other packages using conda-forge: almost always ca-certificates, certifi and openssl; and sometimes major packages like python, numpy etc (all from conda-forge). I suspect these updates are not strictly necessary; those packages get pulled in using some logic along the lines of "in order to install the latest version of somepackage I need python>=3.8 but the current python is 3.7; I can use conda-forge, so I'll get the latest python from conda-forge which is newer than the one in default".
What I would like to accomplish is: install any version of somepackage (not necessarily latest) while installing as little as possible from conda-forge. In particular, if there is a choice between keeping an already installed package and upgrading, I always want to keep; and if there is a choice between default channel and conda-forge, I always want default (even if those choices result in ending up with older versions of the new packages I'm trying to install, and/or their new dependencies - but not if they result in the install being impossible).
How do I accomplish this?
Upvotes: 4
Views: 3614
Reputation: 76740
Generally, I endorse the conclusion in @jakub's answer: Define a reasonable global channel priority and try to avoid using ad hoc specifications via the --channel|-c
argument.
There are some additional options that may be worth pointing out:
Specify that a particular package should come from a given channel with
conda install conda-forge::somepackage
and this will not change the channel priority.
Explicitly list channel priorities in the install
command:
conda install -c defaults -c conda-forge somepackage
which puts defaults with top priority.
Define and manipulate environments through YAML files. YAMLs include a channels section, so you can be explicit about the priority. If you require a new package in the environment, it can be added to the YAML - let's say env.yaml
- and that edit can be transferred to the environment with
conda env update -f env.yaml
Upvotes: 7
Reputation: 19260
how do I tell conda "don't upgrade dependencies"
One can use conda install --freeze-installed PACKAGE...
(documentation) to prevent conda from updating packages that are already installed. This does not, however, seem to prevent updating of packages under the aggressive_update_packages
key of conda's config. The default packages there are ca-certificates
, certifi
, and openssl
(see the default configuration). One can check their own configuration with
conda config --show aggressive_update_packages
install any version of somepackage (not necessarily latest) while installing as little as possible from conda-forge
According to the conda documentation on managing channels, one can do this by putting the conda-forge
channel at the bottom of the list of channels and setting channel_priority: strict
in conda's config.
With strict channel priority, packages in lower priority channels are not considered if a package with the same name appears in a higher priority channel.
The "manage channels" page recommends setting strict as the default and indicates that conda 5.x will set strict as the default value for channel_priority
.
One can write the following to their ~/.condarc
file:
channel_priority: strict
channels:
- defaults
- conda-forge
However, if one uses the -c/--channel
option in conda config
, that channel will take precedence over any other channels. So if one sets their conda config as above but uses conda install -c conda-forge numpy
, then numpy
will be installed from conda-forge
.
Upvotes: 3