How to Share Conda Environments Across Platforms

How to share conda environments across platforms

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

Recommendation: manually create an environment.yaml file and specify or pin
only 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 conda
environments) explicitly recommends that you "Always create your
environment.yml file by hand."

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

Have a look at the readme for
conda-env.

They can be quite simple:

name: basic_analysis
dependencies:
- numpy
- pandas

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

name: stats-web
channels:
- javascript
dependencies:
- 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.

Transferring Conda environments across platforms

If you are working across platforms (osx-64 -> win-64) you'll need to be minimal about what packages you export from the existing environment. While Conda does have a recommended intra-platform procedure for exactly recreating environments, it does not directly translate to the cross-platform situation. Instead, try using:

conda env export --from-history > environment.yml

and then, on the new computer,

conda env create -f environment.yml

This will only export the packages that you have explicitly specified to be in the environment at some point (e.g., using conda install foo). Dependencies will be resolved automatically on the new system. This does not guarantee there still won't be packages that aren't available on Windows, but they should be less frequent and easier to resolve manually (typically by removing them from the YAML or adjusting versions).

Transfer a Conda environment between Ubuntu and Windows

Note the section in the conda docs that deals specifically with this question. When exporting the env, use the from-history flag:

conda env export --from-history

this will make sure that the yml file only contains the packages that you installed explicitly

Anaconda export Environment file

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.

Using a conda env created on windows for linux

Yes and no. Using conda export will enable someone else to exactly replicate your environment. This implicitly assumes you are on the same platform.

Unfortunately, when swapping platforms, you need to handle packages that are platform dependent. The easiest way is just remove them. Keep in mind that if you include a high level package with lots of dependencies, all of those dependencies are looked up/handled by conda.

For example, if you want to include pandas, you don't need to include numpy, qt, matplotlib, and dateutils in your environment spec. Just listing pandas is enough, conda takes care of the rest.

In this way, you may be better off just listing out the bare minimum of your environment requirements by hand in a text editor.

Alternatively, you can use conda export, but you may still need to remove a good number of the build numbers (i.e. =vc17gnad8qt6h) and packages that are Windows only (like wincertstore).



Related Topics



Leave a reply



Submit