The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC F Haydns String Quartet No 53 in D

--

Chapters
00:00 Question
01:26 Accepted answer (Score 486)
01:56 Answer 2 (Score 73)
02:20 Answer 3 (Score 31)
02:43 Thank you

--

Full question
https://stackoverflow.com/questions/4235...

Accepted answer links:
[conda env update]: https://docs.conda.io/projects/conda/en/...
[this answer]: https://stackoverflow.com/a/54825300/226...
[Updating an environment]: https://docs.conda.io/projects/conda/en/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #anaconda #conda

#avk47



ACCEPTED ANSWER

Score 586


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.

Attention: if there is a name tag with a name other than that of your environment in local.yml, the command above will create a new environment with that name. To avoid this, use (thanks @NumesSanguis):

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

See Updating an environment in Conda User Guide.




ANSWER 2

Score 84


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



ANSWER 3

Score 36


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!



ANSWER 4

Score 1


Recently Conda introduced the option to stack environments, which should solve this problem.