Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to back up anaconda environment in Windows 10?

Recently, my anaconda environment got broken due to certain bad conda package upgrade. Due to this back experience, I would like to back up my anaconda environment for future easy recovery.

What I did to back up was to zip up the entire folder at C:\ProgramData\Anaconda3. Is this the correct way?

I am using Windows 10, anaconda python v3.6 64-bit.

like image 957
guagay_wk Avatar asked Aug 31 '18 23:08

guagay_wk


People also ask

Can you export an Anaconda environment?

Anaconda allows you to export a virtual environment into a YAML file. It's simple to understand data serialization language often used to create configuration files. YAML is similar to JSON, but without brackets.

Where are Anaconda environments stored Windows?

The environments created by Conda is always located in /Users/.../anaconda3/envs/ . You may change the default location by using the following command but it is not encouraged.


2 Answers

It doesn't really make sense to zip up a conda environment for back up purposes since there are other ways to do this which may be more appropriate and use the in-built functions designed to do just this.

You can create a .txt version of the conda environment that details each module and version within, and can then be used to re-create the EXACT environment in the future.

# Create list of the environment
conda list --explicit environment_backup.txt

# Use the newly created text file to recreate the environment
conda create --name my_env_name --file environment_backup.txt

See docs for more information on managing conda environments.

N.B. As an additional point, conda environment directories can be fairly large (often >1GB) whereas the txt file created here is ~25KB, offering a clear advantage when archiving something for safe-keeping.

like image 95
tda Avatar answered Sep 21 '22 19:09

tda


There are numerous ways you can achieve that as the way the anaconda website has shared. However, if you have limited or no internet accessibility, using a tool named "conda-pack" is recommended (unfortunately with the same OS for now).

Follow steps below:

conda install -c conda-forge conda-pack

And then on your source machine:

# Pack environment my_env into my_env.tar.gz
$ conda pack -n my_env

# Pack environment my_env into out_name.tar.gz
$ conda pack -n my_env -o out_name.tar.gz

# Pack environment located at an explicit path into my_env.tar.gz
$ conda pack -p /explicit/path/to/my_env

Lastly, on your target machine:

# Unpack environment into directory `my_env`
$ mkdir -p my_env
$ tar -xzf my_env.tar.gz -C my_env

# Use python without activating or fixing the prefixes. Most python
# libraries will work fine, but things that require prefix cleanups
# will fail.
$ ./my_env/bin/python

# Activate the environment. This adds `my_env/bin` to your path
$ source my_env/bin/activate

# Run python from in the environment
(my_env) $ python

# Cleanup prefixes from in the active environment.
# Note that this command can also be run without activating the environment
# as long as some version of python is already installed on the machine.
(my_env) $ conda-unpack

# At this point the environment is exactly as if you installed it here
# using conda directly. All scripts should work fine.
(my_env) $ ipython --version

# Deactivate the environment to remove it from your path
(my_env) $ source my_env/bin/deactivate
like image 26
Pedram Avatar answered Sep 21 '22 19:09

Pedram