How to share conda environments across platforms How to share conda environments across platforms python python

How to share conda environments across platforms


This answer is given with the assumption that you would like to make sure thatthe same versions of the packages that you generally care about are ondifferent platforms and that you don't care about the exact same versions ofall packages in the entire dependency tree. If you are trying to install theexact same version of all packages in your entire dependency tree that has ahigh likelihood of failure since some conda packages have differentdependencies for osx/win/linux. For example, the recipe forotroboptwill install different packages on Win vs. osx/linux, so the environment listwould be different.

Recommendation: manually create an environment.yaml file and specify or pinonly the dependencies that you care about. Let the conda solver do the rest.Probably worth noting is that conda-env (the tool that you use to manage condaenvironments) explicitly recommends that you "Always create yourenvironment.yml file by hand."

Then you would just do conda env create --file environment.yml

Have a look at the readme forconda-env.

They can be quite simple:

name: basic_analysisdependencies:  - numpy  - pandas

Or more complex where you pin dependencies and specify anaconda.org channels toinstall from:

name: stats-webchannels:  - javascriptdependencies:  - python=3.4   # or 2.7 if you are feeling nostalgic  - bokeh=0.9.2  - numpy=1.9  - nodejs=0.10  - flask  - pip:    - Flask-Testing

In either case, you can create an environment with conda env create --file environment.yaml.

NOTE: You may need to use .* as a version suffix if you're using an older version of conda.


Whilst it is possible to create your environment.yml file by hand, you can ensure that your environment works across platforms by using the conda env export --from-history flag.

This will only include packages that you’ve explicitly asked for, as opposed to including every package in your environment.

For example, if you create an environment and install a package conda install python=3.8 numpy, it will install numerous other dependencies as well as python and numpy.

If you then run conda env export > environment.yml, your environment.yml file will include all the additional dependencies conda automatically installed for you.

On the other hand, running conda env export --from-history will just create environment.yml with python=3.8 and numpy and thus will work across platforms.

Answer adapted from the docs.


conda-env export should be used used to export your complete environment to file named my_env.yml.

Check the working solution on getting only prefix on OS X instead of complete dependency including pip.

Step 1: deactivate from the environment if activated. else it will create yml file with only prefix.

Step 2: run below command to export

conda-env export -n my_env > my_env.yml

it will export every required dependency, channel and pip install in a yml file which is importable to share with others.

Step 3: run below command to import

conda-env create -n my_env -f= my_env.yml

it will create the exact environment as is on sharing fellow machine.