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?
conda env create -f ~/CoqGym/coq_gym.yml
(see: stackoverflow.com/questions/54492671/…)
Try using conda env update:
conda activate myenv
conda env update --file local.yml --prune
--prune
uninstalls dependencies which were removed from local.yml
, as pointed out in this answer by @Blink.
Or without the need to activate the environment (thanks @NumesSanguis):
conda env update --name myenv --file local.yml --prune
See Updating an environment in Conda User Guide.
The suggested answer is partially correct. You'll need to add the --prune option to also uninstall packages that were removed from the environment.yml. Correct command:
conda env update -f local.yml --prune
requirements.yml
file has a name:
at the top?
alkamid's answer is on the right lines, but I have found that Conda fails to install new dependencies if the environment is already active. Deactivating the environment first resolves this:
source deactivate;
conda env update -f whatever.yml;
source activate my_environment_name; # Must be AFTER the conda env update line!
-n <environment name>
, but by default it seems to work with the expected environment (maybe the most recently active, or just a default environment choice)
Success story sharing
-f
andfile.yml
. Removing the equals sign will make tab completion work on the.yml
filename.--name env_name
to ignore anyname: foo
tag inlocal.yml
. Also prevents the need to activate myenv first. Full command:conda env update --name env_name --file local.yml
From: stackoverflow.com/a/45525593/3399066 's commentname
parameter, otherwise it creates with this update command