Skip to main content

Conda Environment Recipes

Create an isolated environment instead of adding project packages to base:

conda create --name my-env python=3.12
conda activate my-env
conda install numpy pandas

For a project with an environment.yml, create or update the named environment with:

conda env create --file environment.yml
conda env update --file environment.yml --prune

The first command is the long-supported environment workflow; newer Conda releases may also recommend conda create --file environment.yml. Check the official environment guide when scripting across versions.

Dependency-File Boundary

Do not assume every requirements.txt is a Conda specification. Use the command that matches the file format:

# Conda package specifications, one per line
conda install --file conda-requirements.txt

# pip-style Python requirements, inside the active environment
conda install pip
python -m pip install --requirement requirements.txt

When mixing the two package managers, install Conda packages first and pip-only packages last. Recreating a small environment is usually easier to reason about than repeatedly mutating a conflicted one.

Inspect, Share, and Remove

# Inspect environments and installed packages
conda env list
conda list --name my-env

# Record only explicitly requested packages for a portable starting point
conda env export --name my-env --from-history > environment.yml

# Make a local copy before risky experimentation
conda create --name my-env-copy --clone my-env

# Remove an environment after confirming its exact name
conda remove --name my-env --all

An exported environment is a reconstruction input, not proof that every platform will resolve identical builds. Use an explicit spec or lockfile when byte-for-byte environment reproduction is actually required.