How can you "clone" a conda environment into a root environment?

I would like the Conda root environment to copy all packages in another environment. How can this be done?

+23
source share
3 answers

Option 1 - YAML file

When trying to import packages from the second environment to the root environment:

In the second environment, export the package names to the yaml file:

> conda env export > environment.yml 

then update the first environment (see suggestion below):

 > conda env update -n root -f envoronment.yml 

See also conda env for more details. Alternatively, check out the included Anaconada Navigator desktop software for more clarity.

Suggestion: make a backup of existing environments (see the first command) before attempting to make root changes and verify the desired result by testing these commands in a demo environment.


Option 2 - cloning medium

The --clone flag can be used to clone environments:

 > conda create --name myclone --clone root 

This basically creates a direct copy of the environment.


Option 3 - Spec file

You can also create a specification file to add dependencies from one environment to another:

 > conda list --explicit > spec-file.txt > conda install --name root --file spec-file.txt 

Alternatively, copyable media (similar to cloning):

 > conda create --name myenv --file spec-file.txt 

Note. Spec files only work with environments created in the same OS.

+39
source

To make a copy of your root environment (named base ), you can use the following command; worked for me with Anaconda3-5.0.1:

 conda create --name <env_name> --clone base 

you can get a list of all packages installed in conda using the following command

 conda list -n <env_name> 
+15
source

When setting up a new environment, and I need packages from the base environment in my new one (which often happens), I create the same conda environment using the spec-file.txt with:

list conda --explicit> spec-file.txt

The spec file contains, for example, packages of the base environment.

Then, using the prompt, I install the packages in a new environment:

conda install --name myenv --file spec-file.txt

Packages from the database will be available in the new environment.

The whole process is described in the document: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments

+1
source

Source: https://habr.com/ru/post/1012494/


All Articles