Brian B
Brian B

Reputation: 1450

How to prefer `defaults` numpy over `conda-forge` numpy when installing `conda-forge` package

I prefer using the MKL toolchain from the usual defaults channel provided by Continuum. Like many people, though, I find myself installing quite a few packages from the conda-forge channel.

Consider, for example, the python-graphviz package. The install command is

conda install -c conda-forge python-graphviz

which results in some undesired changes to dependencies

The following packages will be UPDATED:

cvxopt:          1.1.7-py27_0          --> 1.1.9-py27_blas_openblas_201  conda-forge [blas_openblas]
gsl:             2.2.1-h8267d9d_2      --> 2.2.1-blas_openblas_2         conda-forge [blas_openblas]
numpy:           1.13.3-py27hbcc08e0_0 --> 1.13.3-py27_blas_openblas_200 conda-forge [blas_openblas]
scikit-learn:    0.19.1-py27h445a80a_0 --> 0.19.1-py27_blas_openblas_200 conda-forge [blas_openblas]
scipy:           0.19.1-py27h1edc525_3 --> 0.19.1-py27_blas_openblas_202 conda-forge [blas_openblas]

I don't want to change to the OpenBlas numpy, so I manually handle all the dependencies and then

conda install -c conda-forge --no-deps python-graphviz

which works fine but is laborious and invites mistakes.

I had thought that if I added conda-forge as a low priority channel with

conda config --append channels conda-forge

then it would stop trying to override the numpy installation, but this turned out to be untrue. The output of conda config --show now contains, as expected,

channel_alias: https://conda.anaconda.org
channel_priority: True
channels:
  - defaults
  - conda-forge

but if I try installing something (without the command-line switch) with, say, conda install pycwt, then I still get

Package plan for installation in environment /conda:

The following NEW packages will be INSTALLED:

  pycwt:        0.3.0a22-py_0         conda-forge
  tqdm:         4.19.4-py27hdfef72e_0            

The following packages will be UPDATED:

  cvxopt:       1.1.7-py27_0                      --> 1.1.9-py27_blas_openblas_201  conda-forge [blas_openblas]
  gsl:          2.2.1-h8267d9d_2                  --> 2.2.1-blas_openblas_2         conda-forge [blas_openblas]
  numpy:        1.13.3-py27hbcc08e0_0             --> 1.13.3-py27_blas_openblas_200 conda-forge [blas_openblas]
  scikit-learn: 0.19.1-py27h445a80a_0             --> 0.19.1-py27_blas_openblas_200 conda-forge [blas_openblas]
  scipy:        0.19.1-py27h1edc525_3             --> 0.19.1-py27_blas_openblas_202 conda-forge [blas_openblas]

Is there a way to prefer defaults over conda-forge updates when I install conda-forge packages?

Edit: Added more information about conda config output and non-switch behavior

Upvotes: 10

Views: 2559

Answers (3)

merv
merv

Reputation: 76740

A literal translation of the expression

prefer defaults over conda-forge while installing the python-graphviz package from conda-forge

would be

conda install -c defaults -c conda-forge conda-forge::python-graphviz

This works because conda accepts multiple -c arguments, given priority according to order (first is highest, last is lowest).1 The conda-forge:: overrides the priority and only looks for python-graphviz on the conda-forge channel.

It may also be sufficient to simply do:

conda install conda-forge::python-graphviz

which should respect the user's configured channels, except for using conda-forge for the specified package.


[1] You may need to have conda config --set channel_priority strict for this to behave.

Upvotes: 2

Primer
Primer

Reputation: 10302

You might want to use pinned_packages feature of conda config.

Either manually edit your .condarc file (it's location can be seen in the output of conda config --show-sources) by changing/adding these lines:

pinned_packages:
  - defaults::numpy

Or from command line:

conda config --add pinned_packages defaults::numpy

This will ensure that numpy will be only installed / updated from defaults channel and not from conda-forge.

Upvotes: 9

darthbith
darthbith

Reputation: 19597

Adding the channel to the install command makes that channel the highest priority channel. If you add the conda-forge channel to the end of your configuration and do not specify it in the install command you will get dependencies from the first channel that matches them.

Upvotes: 0

Related Questions