Skip to content

Take over an existing conda environment

You just joined a team or lab that uses conda. Someone handed you an environment.yml and told you to conda activate. This tutorial walks through the day-to-day operations: creating an environment from a file, exploring what’s installed, adding packages, handling the conda+pip boundary, and exporting a reproducible environment for teammates.

Prerequisites

Install Miniforge following the Miniforge installation instructions.

Important

Use Miniforge, not Miniconda or Anaconda. Miniforge defaults to the conda-forge channel, which is community-maintained and freely licensed. Miniconda and Anaconda default to the defaults channel, which requires a paid license for commercial use at organizations with more than 200 employees. See Is Conda Actually Free? for the full licensing picture.

After installation, verify conda is available:

conda --version

Understand what you’ve been given

The environment.yml file describes a conda environment. Here is a realistic example (save this as environment.yml to follow along):

environment.yml
name: analysis
channels:
  - conda-forge
dependencies:
  - python=3.12
  - pandas=2.2
  - matplotlib=3.9
  - scikit-learn=1.5
  - jupyter
  - pip:
    - seaborn

The key fields:

  • name: the environment name. You’ll use this with conda activate analysis.
  • channels: where conda fetches packages. conda-forge is the most common community channel.
  • dependencies: packages installed from conda channels. Version pins like python=3.12 lock to a minor version; unpinned packages like jupyter get the latest compatible release.
  • pip: packages installed from PyPI after the conda packages. Some packages (like seaborn in this example) are available on both conda-forge and PyPI. The pip: section is for packages that are only on PyPI or that the team chose to install via pip.

Create the environment

conda env create -f environment.yml

This resolves all dependencies, downloads packages, and creates a named environment. The process can take a few minutes on the first run.

Activate the environment:

conda activate analysis

Your shell prompt changes to show the active environment name. Every python, pip, or jupyter command now uses this environment’s packages.

Explore the environment

List installed packages:

conda list

This shows every package, its version, build string, and channel. The output is long. Filter it to find a specific package:

conda list pandas

Check environment metadata:

conda info

This prints the active environment path, Python version, and conda configuration. The environment lives on disk as a directory (typically under ~/miniforge3/envs/analysis/ or wherever Miniforge is installed).

Add a new dependency

Your work requires a package that wasn’t in the original environment.yml. Install it with conda:

conda install scipy

Conda resolves the new package against everything already installed and updates the environment. If the resolution takes too long or produces conflicts, pin fewer versions in environment.yml or check for incompatible version constraints.

Handle the conda + pip boundary

Sometimes you need a package that only exists on PyPI, not on conda-forge. Install it with pip inside the active conda environment:

pip install watermark

Warning

Mixing conda and pip requires care. Always install conda packages first, then pip packages. If you conda install something after using pip, conda doesn’t know about pip’s packages and can overwrite or break them. The safe ordering is: build the conda environment, then add pip packages at the end.

Check what pip installed (as opposed to conda):

pip list --format=freeze | head -20

The environment.yml captures this split with the pip: subsection under dependencies. When you export the environment later, both conda and pip packages are included.

Export the environment for teammates

After adding packages, export the updated environment so teammates can reproduce it.

For cross-platform sharing, use --from-history:

conda env export --from-history > environment.yml

This exports only the packages you explicitly requested (not platform-specific transitive dependencies), making the file portable across macOS, Linux, and Windows.

Note

--from-history does not capture pip-installed packages. If your environment includes pip packages, add them manually to the pip: section of environment.yml after exporting.

For an exact reproduction on the same platform, export everything:

conda env export > environment-lock.yml

This includes every transitive dependency with exact versions and build strings. It only works on the same OS and architecture.

Remove the environment

When you’re done with an environment or need to start fresh:

conda deactivate
conda env remove -n analysis

Recreate it anytime from the environment.yml file.

Next steps

Last updated on

Please submit corrections and feedback...