Search code examples
pythonconda

Subtle mistake in conda create syntax will install a patch = 0 version of python


I'm creating a new conda environment with no additional packages.

It is interesting to note the difference in the python interpreter version installed with a small change in the conda create syntax...

conda create --name test python=3.11

...installs python 3.11.9 as expected.

However but putting a double == rather than a single = when specifying the python version...

conda create --name test python==3.11

...does not throw any errors but creates an environment containing python 3.11.0, not the 3.11.9 that I was expecting.

This is consistent across 3.9, 3.10, 3.11 and 3.12, all install patch version 0.

I assume the double == is not the correct syntax and that this is not an intended behaviour but this is not caught and certainly confused me for a while.

Windows 10, conda version 23.11.0


Solution

  • It is definitely desired behavior and not a bug: Specifying the version with = is considered a "fuzzy constraint" while == is considered an "exact constraint".

    The Conda Cheat Sheet gives as an example:

    Constraint type Specification Result
    Fuzzy numpy=1.11 1.11.0, 1.11.1, 1.11.2, 1.11.18 etc.
    Exact numpy==1.11 1.11.0

    Similarly, as pointed out by @FlyingTeller, the section Conda Package Specification (subsection Command Line Match Spec Examples) of the conda documentation gives the following examples:

    Example Meaning
    conda install numpy=1.11 The fuzzy constraint numpy=1.11 matches 1.11, 1.11.0, 1.11.1, 1.11.2, 1.11.18, and so on.
    conda install numpy==1.11 The exact constraint numpy==1.11 matches 1.11, 1.11.0, 1.11.0.0, and so on.

    Arguably, this could be better documented with the commands themselves, such as conda create and conda install, where, at the time of writing, no such documentation can be found.