Skip to content

conda-lock - Reproducible Conda Environment Locking Cheatsheet

conda-lock - Reproducible Conda Environment Locking Cheatsheet

conda-lock solves conda’s reproducibility problem. An environment.yml lists requested packages, so solving it on two machines a week apart can produce different versions — the classic “works on my machine.” conda-lock resolves the environment once and writes a lock file with exact versions, builds, and hashes for every platform you target, so installs become deterministic and fast (no solving at install time).

Installation

MethodCommand
pipx (recommended)pipx install conda-lock
condaconda install -c conda-forge conda-lock
pippip install conda-lock
Verifyconda-lock --version

Generating a Lock File

# Lock for multiple platforms from an environment.yml
conda-lock -f environment.yml -p linux-64 -p osx-arm64 -p win-64
FlagPurpose
-f, --fileInput spec (environment.yml, pyproject.toml, meta.yaml)
-p, --platformTarget platform (repeatable)
-k, --kindOutput kind: lock (unified), explicit, env
--lockfileOutput path (default conda-lock.yml)
--check-input-hashSkip re-solving if inputs unchanged

Lock File Kinds

KindProducesUse
lockUnified conda-lock.yml (all platforms)Commit this to git
explicitPer-platform .lock filesconda create --file
envRendered environment.ymlTools expecting a plain env file
# Render per-platform explicit files from the unified lock
conda-lock render -p linux-64

Installing From a Lock

# Create an environment exactly as locked
conda-lock install --name myenv conda-lock.yml

# Or with micromamba (fast)
micromamba create -n myenv -f conda-linux-64.lock
CommandDescription
conda-lock install -n NAMECreate/update the env from a lock
conda-lock install --mambaUse mamba as the solver/installer
conda create --file X.lockInstall an explicit lock directly

Updating Dependencies

# Re-solve everything (new versions allowed)
conda-lock -f environment.yml -p linux-64 -p osx-arm64

# Update just one package, keep the rest pinned
conda-lock --update numpy -f environment.yml -p linux-64
TaskCommand
Full refreshRe-run conda-lock
Targeted bump--update PKG
Verify inputs unchanged--check-input-hash

Including pip Dependencies

# environment.yml
name: myproject
channels: [conda-forge]
dependencies:
  - python=3.12
  - numpy
  - pip
  - pip:
      - some-pypi-only-package==1.2.3

conda-lock resolves both conda and pip dependencies into the same lock file, which is important because mixing the two ad hoc is a common source of broken environments.

CI Pattern

# Deterministic, fast CI installs
- run: conda-lock install --name ci conda-lock.yml
- run: conda run -n ci pytest
PracticeWhy
Commit conda-lock.ymlThe lock is the source of truth
Lock all target platformsDevs on macOS, CI on Linux
Regenerate deliberatelyDependency updates become reviewable diffs
Cache the envLocks make caching reliable

conda-lock vs Alternatives

Aspectconda-lockenvironment.ymlpixiuv
ReproducibleExact pins + hashesNoBuilt-in lockBuilt-in lock
Conda ecosystemYesYesYesNo (PyPI)
Multi-platform lockYesN/AYesYes
Best forLocking existing conda projectsSimple/ad-hoc envsNew conda-based projectsPure-Python projects

For new projects consider pixi (locking built in) or uv for pure-Python; conda-lock retrofits reproducibility onto existing conda workflows.

Resources