Search code examples
pythoncondavirtual-environment

What's the point of the prefix line in conda environment file when creating a new environment?


To save a conda environment and re-create it, I use:

# Save the environment
conda env export > my_conda_env.yml

# Re-create the environment
conda env create --file my_conda_env.yml

# Reactivate the environment
conda activate pytorch 

I notice that my_conda_env.yml contains prefix: /home/franck/anaconda3/envs/pytorch on the last line. What's the point of it?


Solution

  • It specifies the directory to put the environment in.

    Straight from the documentation:

    You can control where a conda environment lives by providing a path to a target directory when creating the environment. For example, the following command will create a new environment in a subdirectory of the current working directory called envs:

    conda create --prefix ./envs jupyterlab=0.35 matplotlib=3.1 numpy=1.16
    

    Or, you could have checked:

    conda env create --help
    

    And it shows:

      -p PATH, --prefix PATH
                            Full path to environment location (i.e. prefix).