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 yourenvironment.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
Change the Colors Within Certain Range to Another Color Using Opencv
Naming Conflict with Built-In Function
Bin Elements Per Row - Vectorized 2D Bincount for Numpy
Changing Iteration Variable Inside for Loop in Python
I Expect 'True' But Get 'None'
Python 3.5 - "Geckodriver Executable Needs to Be in Path"
How to Make My Player Rotate Towards Mouse Position
Wrapping a C Library in Python: C, Cython or Ctypes
What's the Best Practice Using a Settings File in Python
Pyplot Common Axes Labels for Subplots
How to Upgrade to Python 3.6 with Conda
How to Get the Current Time in Milliseconds in Python
Why Doesn't Os.Path.Join() Work in This Case
Reactornotrestartable Error in While Loop with Scrapy
How to Set a Default Parameter Equal to Another Parameter Value
Adding a Legend to Pyplot in Matplotlib in the Simplest Manner Possible