The Python Oracle

Anaconda export Environment file

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay

--

Chapters
00:00 Question
00:38 Accepted answer (Score 336)
01:54 Answer 2 (Score 86)
02:21 Answer 3 (Score 76)
03:14 Answer 4 (Score 15)
03:40 Thank you

--

Full question
https://stackoverflow.com/questions/4127...

Accepted answer links:
[Alex pointed out]: https://stackoverflow.com/questions/4127...

Answer 2 links:
https://pip.pypa.io/en/stable/reference/.../

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #python3x #anaconda #conda

#avk47



ACCEPTED ANSWER

Score 395


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.




ANSWER 2

Score 95


The easiest way to save the packages from an environment to be installed in another computer is:

$ conda list -e > req.txt

then you can install the environment using

$ conda create -n <environment-name> --file req.txt

if you use pip, please use the following commands: reference https://pip.pypa.io/en/stable/reference/pip_freeze/

$ env1/bin/pip freeze > requirements.txt
$ env2/bin/pip install -r requirements.txt



ANSWER 3

Score 92


  • Linux or Mac

conda env export --no-builds | grep -v "prefix" > environment.yml

  • Windows

conda env export --no-builds | findstr -v "prefix" > environment.yml


Rationale: By default, conda env export includes the build information:

$ conda env export
...
dependencies:
  - backcall=0.1.0=py37_0
  - blas=1.0=mkl
  - boto=2.49.0=py_0
...

You can instead export your environment without build info:

$ conda env export --no-builds
...
dependencies:
  - backcall=0.1.0
  - blas=1.0
  - boto=2.49.0
...

Which unties the environment from the Python version and OS.




ANSWER 4

Score 9


  1. First activate your conda environment (the one u want to export/backup)
conda activate myEnv
  1. Export all packages to a file (myEnvBkp.txt)
conda list --explicit > myEnvBkp.txt
  1. Restore/import the environment:
conda create --name myEnvRestored --file myEnvBkp.txt

And if you're using the Mamba or the recent Miniforge3 distribution, use the following commands:

  1. First activate your conda environment (the one u want to export/backup)
mamba activate myEnv
  1. Export all packages to a file (myEnvBkp.txt)
mamba list --explicit > myEnvBkp.txt
  1. Restore/import the environment:
mamba create --name myEnvRestored --file myEnvBkp.txt