Search code examples
pythonpython-3.xanacondaconda

Anaconda export Environment file


How can I make anaconda environment file which could be use on other computers?

I exported my anaconda python environment to YML using conda env export > environment.yml. The exported environment.yml contains this line prefix: /home/superdev/miniconda3/envs/juicyenv which maps to my anaconda's location which will be different on other's pcs.


Solution

  • I can't find anything in the conda specs which allows you to export an environment file without the prefix: ... line. However, like Alex pointed out in the comments, conda doesn't seem to care about the prefix line when creating an environment from the file.

    With that in mind, if you want the other user to have no knowledge of your default install path, you can remove the prefix line with grep before writing to environment.yml.

    conda env export | grep -v "^prefix: " > environment.yml
    

    Either way, the other user then runs:

    conda env create -f environment.yml
    

    and the environment will get installed in their default conda environment path.

    If you want to specify a different install path than the default for your system (not related to 'prefix' in the environment.yml), just use the -p flag followed by the required path.

    conda env create -f environment.yml -p /home/user/anaconda3/envs/env_name
    

    Note that Conda recommends creating the environment.yml by hand, which is especially important if you are wanting to share your environment across platforms (Windows/Linux/Mac). In this case, you can just leave out the prefix line.