Differences between revisions 1 and 39 (spanning 38 versions)
Revision 1 as of 2019-05-10 15:09:37
Size: 7330
Editor: stroth
Comment:
Revision 39 as of 2019-05-31 07:02:16
Size: 12128
Editor: stroth
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
= Set up a python development environment for data science =
The following procedure shows how to set up a python development environment with the [[https://conda.io/|conda]] packet manager and install [[https://pytorch.org/|pytorch]] and [[https://www.tensorflow.org/|tensorflow]].

== Install conda ==
 * Time to install: ~1'
 * Space required: ~350M

To provide conda, the minimal anaconda distribution '''miniconda''' can be installed and configured for the D-ITET infrastructure with the following bash script:
= Setting up a personal python development infrastructure =
This page shows how to [[#Installing_conda|set up a personal python development infrastructure]], how to [[#Using_conda|use it]], how to [[#Maintenance|maintain it]] and [[#Backup|make backups of your project environments]].

Some [[#Installation_examples|examples for software installation]] in the field of data sciences are provided.

The infrastructure is driven by the [[https://conda.io/|conda]] packet manager which accesses the [[https://repo.continuum.io/pkgs/|Anaconda repositories]] to install software.

After familiarizing yourself with `conda`, read this [[Programming/Languages/GPUCPU|collection of hints and explanations]] about available platforms on which to use your infrastructure and particularities of the software packages involved.

== Installing conda ==
 * Time to install: ~1.5 minutes
 * Space required: ~370M

To provide `conda`, the minimal anaconda distribution '''miniconda''' can be installed and configured for the D-ITET infrastructure with the following bash script:
Line 14: Line 20:
# Locations to store environments
LOCAL_SCRATCH="/scratch/${USER}"
# If local scratch is made available through scratch_net, use its path in
# order to be able to access it on other hosts through scratch_net
scratch_net="/scratch_net/$(hostname -s)"
if mountpoint -q "${scratch_net}"; then
    LOCAL_SCRATCH="${scratch_net}/${USER}"
else
    LOCAL_SCRATCH="/scratch/${USER}"
fi
Line 17: Line 30:

# Locations for conda installation, packet cache and environments
# Replace NET_SCRATCH with LOCAL_SCRATCH according to your needs
CONDA_INSTALL_DIR="${NET_SCRATCH}/conda"
CONDA_PACKET_CACHE="${NET_SCRATCH}/conda_pkgs"
CONDA_ENV_DEFAULT="${NET_SCRATCH}/conda_envs"
CONDA_ENV_LOCAL="${LOCAL_SCRATCH}/conda_envs"
Line 21: Line 41:
line=$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' |tr ' ' '-')

# Display underlined title to improve readability of script output
function title()
{
    echo
    echo "$@"
    echo "${line}"
}
Line 25: Line 55:
title 'Downloading and installing conda'
Line 27: Line 58:
    && ./miniconda.sh -b -p "${NET_SCRATCH}/conda" \     && ./miniconda.sh -b -p "${CONDA_INSTALL_DIR}" \
Line 31: Line 62:
eval "$(${NET_SCRATCH}/conda/bin/conda shell.bash hook)"
conda config --add pkgs_dirs "${NET_SCRATCH}/conda_pkgs" --system
conda config --add envs_dirs "${LOCAL_SCRATCH}/conda_envs" --system
conda config --add envs_dirs "${NET_SCRATCH}/conda_envs" --system
title 'Configuring conda:'
eval "$(${CONDA_INSTALL_DIR}/bin/conda shell.bash hook)"
conda config --add pkgs_dirs "${CONDA_PACKET_CACHE}" --system
conda config --add envs_dirs "${CONDA_ENV_LOCAL}" --system
conda config --add envs_dirs "${CONDA_ENV_DEFAULT}" --system
Line 38: Line 70:
# Update conda and conda base environment
title 'Updating conda and conda base environment:'
conda update conda --yes
conda update -n 'base' --update-all --yes

# Clean installation
title 'Removing unused packages and caches:'
conda clean --all --yes

# Display information about this conda installation
title 'Information about this conda installation:'
conda info
Line 39: Line 84:
echo
echo
'Initialize conda immediately:'
echo "eval \"\$(${NET_SCRATCH}/conda/bin/conda shell.bash hook)\""
echo
echo
'Automatically initialize conda for furure shell sessions:'
echo "echo 'eval \"\$(${NET_SCRATCH}/conda/bin/conda shell.bash hook)\"' >> ${HOME}/.bashrc"
title 'Initialize conda immediately:'
echo "eval \"\$(${CONDA_INSTALL_DIR}/bin/conda shell.bash hook)\""
title 'Automatically initialize conda for future shell sessions:'
echo "echo '[[ -f ${CONDA_INSTALL_DIR}/bin/conda ]] && eval \"\$(${CONDA_INSTALL_DIR}/bin/conda shell.bash hook)\"' >> ${HOME}/.bashrc"
Line 47: Line 90:
echo
echo
'Completely remove conda:'
echo "rm -r ${NET_SCRATCH}/conda ${NET_SCRATCH}/conda_pkgs ${NET_SCRATCH}/conda_envs ${LOCAL_SCRATCH}/conda_envs ${HOME}/.conda"
title 'Completely remove conda:'
echo "rm -r ${CONDA_INSTALL_DIR} ${CONDA_INSTALL_DIR}_pkgs ${CONDA_INSTALL_DIR}_envs ${LOCAL_SCRATCH}/conda_envs ${HOME}/.conda"
Line 52: Line 94:
{{{#!highlight bash numbers=disable {{{
Line 56: Line 98:
{{{#!highlight bash numbers=disable
./install_conda
}}}
Choose your preferred method of initializing `conda` as recommended by the script.

== Conda storage locations ==
{{{
./install_conda.sh
}}}
 * [[#conda-storage-locations|Storage locations]] can be changed by adapting the variables starting with `CONDA_`.
 * When the script ends it prints out information about the installation, commands to initialize `conda` immediately or every time you log in and a command to completely remove your `conda` installation.
 * Choose your preferred method of initializing `conda` as recommended by the script and note down the deletion command.

== conda storage locations ==
Line 65: Line 109:
||`/itet-stor/$USER/net_scratch/conda_envs`||Virtual environments on NAS||
||`/scratch/$USER/conda_envs`||Virtual environments on local disk||
||`/itet-stor/$USER/net_scratch/conda_envs`||Virtual environments on NAS where startup time is not important||
||`/scratch/$USER/conda_envs`||[[#Creates_the_environment_.22my_env.22_in_the_specified_location|Virtual environments on local disk]] which need to start fast||
Line 68: Line 112:
The purpose of this configuration is to store reproducible and space consuming data outside of your `$HOME` to prevent using up your quota.

== Using Conda ==
`conda` allows to seperate installed software packages from each other by creating so-called ```environments```. Using environments is best practice to generate deterministic and reproducible tools.

The purpose of this configuration is to store data according to its importance and prevent using up your quota. If you intend to deviate from the default configuration, consult the [[Services/StorageOverview|storage overview]] to choose your storage locations adequately and follow these recommendations:

 * Reproducible, space consuming data like environments and package cache belongs into storage class ''SCRATCH''
 * Code written by yourself should be backuped regularly. It consumes a small amount of space therefore it's ideal location is in storage class ''HOME'' and additionally checked into your [[https://git.ee.ethz.ch/users/sign_in|git repository]].
 * Data generated over a long time period which would be time consuming to recreate from scratch and is in use regularly should be stored in the storage class ''PROJECT''.
 * Data generated as a final result which is not needed for ongoing work but needs to be available for later generations should be stored in the storage class ''ARCHIVE''.

== Using conda ==
`conda` allows to seperate installed software packages from each other by creating so-called ''environments''. Using environments is best practice to generate deterministic and reproducible tools.
Line 74: Line 124:
This means the dependency installed in an environment with both packages together might have a lower version number than in environments separating both packages. This means the dependency installed in an environment with both packages together might have a lower version number than in environments seperating both packages.
Line 78: Line 128:
For a complete guide to `conda` see the [[https://conda.io/projects/conda/en/latest/index.html|official documentation]].

=== Common commands ===
Common commands to get you started are listed here:
 * `conda create --name my_env package1 package2`
 . creates an environment called "my_env" with packages "package1" and "package2" installed
 * `conda activate my_env`
 . activates the environment called ''my_env''
 * `conda deactivate`
 . deactivates the current environment
 * `conda env list`
 . lists available environments
 * `conda remove --name my_env --all`
 . removes the environment called ''my_env''
 * `conda create --name cloned_env --clone original_env`
 . creates a cloned environment named ''cloned_env'' from ''original_env''
 * `conda env export > my_env.yml`
 . exports the active environment definition to the file ''my_env.yml''
 * `conda env create --file my_env.yml`
 . recreates a previously exported environment
 * `conda list`
 .lists packages installed in the active environment
 * `conda create --prefix /scratch/$USER/conda_envs/my_env`
 . creates the environment ''my_env'' in the specified location
The name of the default environment is `base`.
For a complete guide to `conda` see the [[https://conda.io/projects/conda/en/latest/index.html|official documentation]].

The official [[https://conda.io/projects/conda/en/latest/user-guide/cheatsheet.html|cheat sheet]] contains a compact summary of common commands. An abbreviated list to get you started is shown below.
Line 105: Line 133:
 * Time to install: ~5' per environment
 * Space required: ~1.5G packages, 3G per environment

The following examples show how to install `pytorch` with CUDA toolkit 9, 10 and for CPU as well as `tensorflow` in the same three variants:
For `conda`, `python` itself is just a software package as any other. After analyzing all packages to be installed it decides which `python` version works for the whole environment. This means different environments may contain differing versions of `python`.

==== Creating an environment with a specific python version ====
 * Time to install: ~1 minute
 * Space required: ~140M
{{{
conda create --name py37 python=3.7.3
}}}
==== Creating an environment with the GPU version of pytorch and CUDA toolkit 10 ====
 * Time to install: ~5 minutes
 * Space required: ~2.5G
{{{
conda create --name pytcu10 pytorch torchvision cudatoolkit=10.0 --channel pytorch
}}}
==== Creating an environment with the GPU version of tensorflow and CUDA toolkit 10 ====
 * Time to install: ~5 minutes
 * Space required: ~2G
{{{
conda create --name tencu10 tensorflow-gpu cudatoolkit=10.0
}}}

=== Environments ===
`conda` automatically installs a default environment called ''base'' with a `python` interpreter, [[https://pypi.org/project/pip/|pip]] and other tools to start coding in python. Whether you want to use and extend this environment or create your own is up to you. At the time of writing this information it is not possible to remove the base environment.
==== Create an environment called "my_env" with packages "package1" and "package2" installed ====
{{{
conda create --name my_env package1 package2
}}}
==== Activate the environment called "my_env" ====
{{{
conda activate my_env
}}}
==== Deactivate the current environment ====
{{{
conda deactivate
}}}
==== List available environments ====
{{{
conda env list
}}}
==== Remove the environment called "my_env" ====
{{{
conda remove --name my_env --all
}}}
==== Create a cloned environment named "cloned_env" from "original_env" ====
{{{
conda create --name cloned_env --clone original_env
}}}
==== Export the active environment definition to the file "my_env.yml" ====
This command is also the basis for [[#Backup|backing up]] an environment.
{{{
conda env export > my_env.yml
}}}
==== Recreate a previously exported environment ====
{{{
conda env create --file my_env.yml
}}}
==== Creates the environment "my_env" in the specified location ====
This example is for creating the environment on local scratch for faster disk access
{{{
conda create --prefix /scratch/$USER/conda_envs/my_env
}}}
==== Update an active environment ====
Make sure to create a [[#Backup|backup]] by exporting the active environment before updating.
{{{
conda update --update-all
}}}

=== Packages ===
==== Search for a package named "package1" ====
{{{
conda search package1
}}}
==== Install the package named "package1" in the active environment ====
{{{
conda install package1
}}}
==== List packages installed in the active environment ====
{{{
conda list
}}}
==== Add software channels ====
The list of available software can be extended by adding channels of selected repositories.
The priority of the channels is set in order of configuration. In the following example, [[https://conda-forge.org/|Conda-Forge]] has the highest priority over [[https://bioconda.github.io/|Bioconda]], with the default channel at the lowest priority.
{{{
conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge
}}}
==== Show software channels ====
The following command shows the available channels in order of priority (highest first):
{{{
conda config --show channels
}}}
=== Miscellaneous ===
==== Display information about the current conda installation ====
{{{
conda info
}}}

=== Maintenance ===
The cache of installed packages will consume a lot of space over time. The default location set for the package cache resides on [[Services/NetScratch|NetScratch]], the terms of use for this storage area require you to clean your cache regularly.
==== Remove index cache, lock files, unused cache packages, and tarballs ====
{{{
conda clean --all
}}}
==== Update conda without any active environment ====
{{{
conda update conda
}}}

=== Backup ===
Regular backups are recommended to be able to reproduce an environment used at a certain point in time. Before installing or updating an environment, a backup should always be created in order to be able to revert the changes.

It is not necessary to backup environments themselves, it is sufficient to backup the files of environment exports to recreate them exactly.

For a simple backup of all environments the following script can be used:
Line 111: Line 250:
conda create --name pytcu9 pytorch torchvision cudatoolkit=9.0 --channel pytorch
conda create --name pytcu10 pytorch torchvision cudatoolkit=10.0 --channel pytorch
conda create --name pytcpu pytorch-cpu torchvision-cpu --channel pytorch
conda create --name tencu9 tensorflow-gpu cudatoolkit=9.0
conda create --name tencu10 tensorflow-gpu cudatoolkit=10.0
conda create --name tencpu tensorflow --channel intel
}}}

=== Testing installations ===

==== Testing pytorch ====
To verify if your installation of `pytorch` is working, run the following python code:
{{{#!highlight python numbers=disable
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
}}}
The output should look something like:
{{{
tensor([[0.4813, 0.8839, 0.1568],
        [0.0485, 0.9338, 0.1582],
        [0.1453, 0.5322, 0.8509],
        [0.2104, 0.4154, 0.9658],
        [0.6050, 0.9571, 0.3570]])
}}}
To verify if CUDA is available for `pytorch`, run the following code:
{{{#!highlight python numbers=disable
import torch
torch.cuda.is_available()
}}}
It should return ''True''.

==== Testing TensorFlow ====
The following code prints information about your `tensorflow` installation:
{{{#!highlight python numbers=disable
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
}}}
Look for lines containing `device: XLA_`, they show which CPU/GPU devices are available.

A line containing `cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version` means the NVIDIA driver is not compatible with the CUDA toolkit (see below).

== NVIDIA CUDA Toolkit ==
Which version of the CUDA toolkit is usable depends on the version of the NVIDIA driver installed on the machine you run your programs. The version can be checked by issuing the command `nvidia-smi` and looking for the number next to the text ''Driver Version''.

The CUDA compatibility document by NVIDIA shows a [[https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver|dependency matrix]] matching driver and toolkit versions.
#!/bin/bash

BACKUP_DIR="${HOME}/conda_env_backup"
MY_TIME_FORMAT='%Y-%m-%d_%H-%M-%S'

NOW=$(date "+${MY_TIME_FORMAT}")
[[ ! -d "${BACKUP_DIR}" ]] && mkdir "${BACKUP_DIR}"
ENVS=$(conda env list |grep '^\w' |cut -d' ' -f1)
for env in $ENVS; do
    echo "Exporting ${env} to ${BACKUP_DIR}/${env}_${NOW}.yml"
    conda env export --name "${env}"> "${BACKUP_DIR}/${env}_${NOW}.yml"
done
}}}

Setting up a personal python development infrastructure

This page shows how to set up a personal python development infrastructure, how to use it, how to maintain it and make backups of your project environments.

Some examples for software installation in the field of data sciences are provided.

The infrastructure is driven by the conda packet manager which accesses the Anaconda repositories to install software.

After familiarizing yourself with conda, read this collection of hints and explanations about available platforms on which to use your infrastructure and particularities of the software packages involved.

Installing conda

  • Time to install: ~1.5 minutes
  • Space required: ~370M

To provide conda, the minimal anaconda distribution miniconda can be installed and configured for the D-ITET infrastructure with the following bash script:

#!/bin/bash

# If local scratch is made available through scratch_net, use its path in
# order to be able to access it on other hosts through scratch_net
scratch_net="/scratch_net/$(hostname -s)"
if mountpoint -q "${scratch_net}"; then
    LOCAL_SCRATCH="${scratch_net}/${USER}"
else
    LOCAL_SCRATCH="/scratch/${USER}"
fi

NET_SCRATCH="/itet-stor/${USER}/net_scratch"

# Locations for conda installation, packet cache and environments
# Replace NET_SCRATCH with LOCAL_SCRATCH according to your needs
CONDA_INSTALL_DIR="${NET_SCRATCH}/conda"
CONDA_PACKET_CACHE="${NET_SCRATCH}/conda_pkgs"
CONDA_ENV_DEFAULT="${NET_SCRATCH}/conda_envs"
CONDA_ENV_LOCAL="${LOCAL_SCRATCH}/conda_envs"

# Installer of choice for conda
CONDA_INSTALLER_URL='https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh'

line=$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' |tr ' ' '-')

# Display underlined title to improve readability of script output
function title()
{
    echo
    echo "$@"
    echo "${line}"
}

# Unset pre-existing python paths
[[ -z ${PYTHONPATH} ]] || unset PYTHONPATH

# Downlad latest version of miniconda and install it
title 'Downloading and installing conda'
wget -O miniconda.sh "${CONDA_INSTALLER_URL}" \
    && chmod +x miniconda.sh \
    && ./miniconda.sh -b -p "${CONDA_INSTALL_DIR}" \
    && rm ./miniconda.sh

# Configure conda
title 'Configuring conda:'
eval "$(${CONDA_INSTALL_DIR}/bin/conda shell.bash hook)"
conda config --add pkgs_dirs "${CONDA_PACKET_CACHE}" --system
conda config --add envs_dirs "${CONDA_ENV_LOCAL}" --system
conda config --add envs_dirs "${CONDA_ENV_DEFAULT}" --system
conda config --set auto_activate_base false
conda deactivate

# Update conda and conda base environment
title 'Updating conda and conda base environment:'
conda update conda --yes
conda update -n 'base' --update-all --yes

# Clean installation
title 'Removing unused packages and caches:'
conda clean --all --yes

# Display information about this conda installation
title 'Information about this conda installation:'
conda info

# Show how to initialize conda
title 'Initialize conda immediately:'
echo "eval \"\$(${CONDA_INSTALL_DIR}/bin/conda shell.bash hook)\""
title 'Automatically initialize conda for future shell sessions:'
echo "echo '[[ -f ${CONDA_INSTALL_DIR}/bin/conda ]] && eval \"\$(${CONDA_INSTALL_DIR}/bin/conda shell.bash hook)\"' >> ${HOME}/.bashrc"

# Show how to remove conda
title 'Completely remove conda:'
echo "rm -r ${CONDA_INSTALL_DIR} ${CONDA_INSTALL_DIR}_pkgs ${CONDA_INSTALL_DIR}_envs ${LOCAL_SCRATCH}/conda_envs ${HOME}/.conda"

Save this script as install_conda.sh, make it executable with

chmod +x install_conda.sh

and execute the script by issuing

./install_conda.sh
  • Storage locations can be changed by adapting the variables starting with CONDA_.

  • When the script ends it prints out information about the installation, commands to initialize conda immediately or every time you log in and a command to completely remove your conda installation.

  • Choose your preferred method of initializing conda as recommended by the script and note down the deletion command.

conda storage locations

The directories listed in the command for complete conda removal contain the following data:

/itet-stor/$USER/net_scratch/conda

The miniconda installation

/itet-stor/$USER/net_scratch/conda_pkgs

Downloaded packages

/itet-stor/$USER/net_scratch/conda_envs

Virtual environments on NAS where startup time is not important

/scratch/$USER/conda_envs

Virtual environments on local disk which need to start fast

/home/$USER/.conda

Personal conda configuration

The purpose of this configuration is to store data according to its importance and prevent using up your quota. If you intend to deviate from the default configuration, consult the storage overview to choose your storage locations adequately and follow these recommendations:

  • Reproducible, space consuming data like environments and package cache belongs into storage class SCRATCH

  • Code written by yourself should be backuped regularly. It consumes a small amount of space therefore it's ideal location is in storage class HOME and additionally checked into your git repository.

  • Data generated over a long time period which would be time consuming to recreate from scratch and is in use regularly should be stored in the storage class PROJECT.

  • Data generated as a final result which is not needed for ongoing work but needs to be available for later generations should be stored in the storage class ARCHIVE.

Using conda

conda allows to seperate installed software packages from each other by creating so-called environments. Using environments is best practice to generate deterministic and reproducible tools.

conda takes care of dependencies common to the packages it is asked to install. If two packages have a common dependency but define a differing range of version requirements of said dependency, conda chooses the highest common version number. This means the dependency installed in an environment with both packages together might have a lower version number than in environments seperating both packages.

It is best practice to seperate packages in different environments if they don't need to interact.

For a complete guide to conda see the official documentation.

The official cheat sheet contains a compact summary of common commands. An abbreviated list to get you started is shown below.

Installation examples

For conda, python itself is just a software package as any other. After analyzing all packages to be installed it decides which python version works for the whole environment. This means different environments may contain differing versions of python.

Creating an environment with a specific python version

  • Time to install: ~1 minute
  • Space required: ~140M

conda create --name py37 python=3.7.3

Creating an environment with the GPU version of pytorch and CUDA toolkit 10

  • Time to install: ~5 minutes
  • Space required: ~2.5G

conda create --name pytcu10 pytorch torchvision cudatoolkit=10.0 --channel pytorch

Creating an environment with the GPU version of tensorflow and CUDA toolkit 10

  • Time to install: ~5 minutes
  • Space required: ~2G

conda create --name tencu10 tensorflow-gpu cudatoolkit=10.0

Environments

conda automatically installs a default environment called base with a python interpreter, pip and other tools to start coding in python. Whether you want to use and extend this environment or create your own is up to you. At the time of writing this information it is not possible to remove the base environment.

Create an environment called "my_env" with packages "package1" and "package2" installed

conda create --name my_env package1 package2

Activate the environment called "my_env"

conda activate my_env

Deactivate the current environment

conda deactivate

List available environments

conda env list

Remove the environment called "my_env"

conda remove --name my_env --all

Create a cloned environment named "cloned_env" from "original_env"

conda create --name cloned_env --clone original_env

Export the active environment definition to the file "my_env.yml"

This command is also the basis for backing up an environment.

conda env export > my_env.yml

Recreate a previously exported environment

conda env create --file my_env.yml

Creates the environment "my_env" in the specified location

This example is for creating the environment on local scratch for faster disk access

conda create --prefix /scratch/$USER/conda_envs/my_env

Update an active environment

Make sure to create a backup by exporting the active environment before updating.

conda update --update-all

Packages

Search for a package named "package1"

conda search package1

Install the package named "package1" in the active environment

conda install package1

List packages installed in the active environment

conda list

Add software channels

The list of available software can be extended by adding channels of selected repositories. The priority of the channels is set in order of configuration. In the following example, Conda-Forge has the highest priority over Bioconda, with the default channel at the lowest priority.

conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge

Show software channels

The following command shows the available channels in order of priority (highest first):

conda config --show channels

Miscellaneous

Display information about the current conda installation

conda info

Maintenance

The cache of installed packages will consume a lot of space over time. The default location set for the package cache resides on NetScratch, the terms of use for this storage area require you to clean your cache regularly.

Remove index cache, lock files, unused cache packages, and tarballs

conda clean --all

Update conda without any active environment

conda update conda

Backup

Regular backups are recommended to be able to reproduce an environment used at a certain point in time. Before installing or updating an environment, a backup should always be created in order to be able to revert the changes.

It is not necessary to backup environments themselves, it is sufficient to backup the files of environment exports to recreate them exactly.

For a simple backup of all environments the following script can be used:

#!/bin/bash

BACKUP_DIR="${HOME}/conda_env_backup"
MY_TIME_FORMAT='%Y-%m-%d_%H-%M-%S'

NOW=$(date "+${MY_TIME_FORMAT}")
[[ ! -d "${BACKUP_DIR}" ]] && mkdir "${BACKUP_DIR}"
ENVS=$(conda env list |grep '^\w' |cut -d' ' -f1)
for env in $ENVS; do
    echo "Exporting ${env} to ${BACKUP_DIR}/${env}_${NOW}.yml"
    conda env export --name "${env}"> "${BACKUP_DIR}/${env}_${NOW}.yml"
done

Programming/Languages/Conda (last edited 2024-04-18 08:22:58 by stroth)