问题
I'd like the root environment of conda to copy all of the packages in another environment. How can this be done?
回答1:
Option 1 - YAML file
When trying to import packages from a second environment into the root environment:
Within the second environment, export package names to a 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, consider the bundled Anaconada Navigator desktop program for a more graphical experience.
Suggestion: backup your existing environments (see first command) before attempting changes to root and verify the desired outcome by testing these commands in a demo environment.
Option 2 - Cloning an environment
The --clone flag can be used to clone environments (see @DevC's post):
> conda create --name myclone --clone root
This basically creates a direct copy of an environment.
Option 3 - Spec file
You can also make a spec file to add dependencies from one env to another (see @Ormetrom):
> conda list --explicit > spec-file.txt
> conda install --name root --file spec-file.txt
Alternatively, replicate environments (similar to cloning):
> conda create --name myenv --file spec-file.txt
Note: Spec files only work with environments created on the same OS.
回答2:
To make a copy of your root environment (named base), you can use following command; worked for me with Anaconda3-5.0.1:
conda create --name <env_name> --clone base
you can list all the packages installed in conda environment with following command
conda list -n <env_name>
回答3:
When setting up a new environment and I need the packages from the base environment in my new one (which is often the case) I am building in the prompt a identical conda environment by using a spec-file.txt with:
conda list --explicit > spec-file.txt
The spec-file includes the packages of for example the base environment.
Then using the prompt I install the the packages into the new environment:
conda install --name myenv --file spec-file.txt
The packages from base are then available in the new environment.
The whole process is describe in the doc: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments
来源:https://stackoverflow.com/questions/40700039/how-can-you-clone-a-conda-environment-into-the-root-environment