How to prevent conda updating packages when using 2 `requirements.txt`

Viewed 675

Context

I have to install two packages from Gitlab (not available on any conda or pip channels due to copyright restrictions). The requirements of the first package contain

numpy>=1.16,<1.17

The requirements of the second state just

numpy

Here is a simplified MWE of what I'm doing:

conda create -n test2
conda activate test2
conda install "numpy>=1.16,<1.17"
conda install --freeze-installed numpy

Result

Conda first installs a 1.16.* version of numpy and then wants to update it to v. 1.18, when the last command is launched:

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/user/miniconda3/envs/test2

  added / updated specs:
    - numpy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    numpy-1.18.5               |   py38h8854b6b_0         5.2 MB  conda-forge
    ------------------------------------------------------------
                                           Total:         5.2 MB

The following packages will be UPDATED:

  numpy                               1.16.5-py38h95a1406_0 --> 1.18.5-py38h8854b6b_0


Proceed ([y]/n)? n

Expected behavior

When I install both, I would like to just have numpy=1.16.* installed in the end.

Question

The --freeze-installed option seems to only apply to dependencies. I was not able to find a similar option that would not update the main package, if the new requirement does not conflict with the installed verion. Something like --no-update. Does anyone have ideas on how this can be achieved?

Surely, I can inverse the order of the install commands in this particular MWE, but it does not solve the general problem of having 2 requirements files with different but compatible specifications.

1 Answers

When you pass all requirements to a single conda install command instead of two subsequent calls, conda's solver will try to satisfy all of the dependencies at once. This will give you the expected outcome that the dependencies numpy>=1.16,<1.17 and numpy get resolved to a 1.16.x version of numpy.

When you are working with multiple requirement files, you can pass the --file argument multiple times to provide all the dependencies in one go.

Related