How to update an existing Conda environment with a .yml file

tilikoom picture tilikoom · Feb 20, 2017 · Viewed 81.7k times · Source

How can a pre-existing conda environment be updated with another .yml file. This is extremely helpful when working on projects that have multiple requirement files, i.e. base.yml, local.yml, production.yml, etc.

For example, below is a base.yml file has conda-forge, conda, and pip packages:

base.yml

name: myenv
channels:
  - conda-forge
dependencies:
  - django=1.10.5
  - pip:
    - django-crispy-forms==1.6.1

The actual environment is created with: conda env create -f base.yml.

Later on, additional packages need to be added to base.yml. Another file, say local.yml, needs to import those updates.

Previous attempts to accomplish this include:

creating a local.yml file with an import definition:

channels:

dependencies:
  - pip:
    - boto3==1.4.4
imports:
  - requirements/base. 

And then run the command: conda install -f local.yml.

This does not work. Any thoughts?

Answer

alkamid picture alkamid · May 9, 2017

Try using conda env update:

conda activate myenv
conda env update --file local.yml

Or without the need to activate the environment (thanks @NumesSanguis):

conda env update --name myenv --file local.yml