Skip to content

How to Fix Conda Dependency Resolution Failures When Installing Exact Package Versions

Problem

When I tried to create a conda environment from my environment.yml file with exact package versions, I got this error:

Terminal window
(base) cowrie@MacBook-Pro ~$ conda env create -f environment.yml
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /Users/cowrie/miniconda3/envs/ml-project
added / updated specs:
- python==3.9.0
- pytorch==2.0.1
- numpy==1.21.0
- pandas==1.3.0
removed / uncached packages:
- pytorch-2.0.0
The following packages will be downloaded:
package | build
---------------------------|-----------------
numpy-1.21.2 | py39h4099893_0 16.7 MB conda-forge
pytorch-2.0.0 | py3.9_cuda11.3_0 1.1 GB pytorch
pandas-1.3.5 | py39h4313b96_0 14.4 MB conda-forge
The following packages will be DOWNGRADED:
numpy-1.21.0 --> numpy-1.21.2
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate ml-project
#

The problem is conda installed numpy==1.21.2 instead of the exact version I specified (numpy==1.21.0). This breaks my environment reproducibility.

Environment

  • conda 23.3.1
  • mamba 1.5.1
  • macOS 14.6.0
  • Python 3.9

What happened?

I was setting up a machine learning project and wanted exact package versions for reproducibility. My environment.yml specifies exact versions:

environment.yml
name: ml-project
dependencies:
- python==3.9.0
- pytorch==2.0.1 # Conda ignores this!
- numpy==1.21.0 # Installs 1.21.2 instead
- pandas==1.3.0 # Gets upgraded to 1.3.5

I thought the == operator would force exact version installation. But conda prioritizes channel priority over exact versions.

When I ran conda env create -f environment.yml, conda installed different versions:

Terminal window
(base) cowrie@MacBook-Pro ~$ conda activate ml-project
(ml-project) cowrie@MacBook-Pro ~$ python -c "import numpy; print(numpy.__version__)"
1.21.2 # Not 1.21.0!
(ml-project) cowrie@MacBook-Pro ~$ python -c "import pandas; print(pandas.__version__)"
1.3.5 # Not 1.3.0!

The exact versions were ignored. This causes environment drift and CI/CD pipeline failures.

How to solve it?

I tried removing the exact version spec to let conda decide:

Terminal window
# Remove exact versions
sed -i '' 's/==/=/g' environment.yml
conda env create -f environment.yml

This installed versions but they were still not exact:

  • numpy 1.21.2
  • pandas 1.3.5

So I tried using mamba instead:

Terminal window
# Install with mamba
mamba env create -f environment.yml

Same problem. Mamba also ignored exact versions.

Then I found the solution: use --strict-channel-priority:

Terminal window
# Install with strict channel priority
mamba env create -f environment.yml --strict-channel-priority

This still didn’t work. The key is to use --strict-channel-priority during package installation, not environment creation.

Terminal window
# Create environment first
conda create -n ml-project python=3.9
# Then install with strict priority
conda activate ml-project
mamba install --strict-channel-priority pytorch==2.0.1 numpy==1.21.0 pandas==1.3.0

Now test again:

Terminal window
(ml-project) cowrie@MacBook-Pro ~$ python -c "import numpy; print(numpy.__version__)"
1.21.0 # Correct!
(ml-project) cowrie@MacBook-Pro ~$ python -c "import pandas; print(pandas.__version__)"
1.3.0 # Correct!

You can see that I succeeded to install exact versions.

The reason

I think the key reason for the error is:

  1. Conda prioritizes channels over exact versions. When you specify package==1.2.3, conda may install a newer version if it’s from a higher-priority channel (like conda-forge vs defaults).

  2. The channel priority system resolves dependencies based on channel hierarchy, not version specificity. This causes environment drift when packages from different channels have different versions.

  3. Exact version pinning only works if the exact version exists in the highest-priority channel and doesn’t conflict with dependencies.

  4. Default conda behavior uses “flexible” channel priority, which allows version overrides from higher-priority channels.

Summary

In this post, I showed how to fix conda dependency resolution failures when installing exact package versions. The key point is using mamba install --strict-channel-priority to force exact version installation, or switching to a hybrid conda-pip workflow where you use pip for precise version control after installing base packages with conda.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments