bash script to backup all conda environment lists
#!bin/bash
NOW=$(date "+%Y-%m-%d")
CONDA_BASE=$(conda info --base)
CONDA_FUNCTION="etc/profile.d/conda.sh"
CONDA="$CONDA_BASE/$CONDA_FUNCTION"
source $CONDA
mkdir ./condaenvs-$NOW
ENVS=$(conda env list | grep '^\w' | cut -d' ' -f1)
for env in $ENVS; do
conda activate $env
conda env export > ./condaenvs-$NOW/$env.yml
echo "Exporting $env"
done
python to backup all conda environment lists
import subprocess as sub
import pandas as pd
# create list of current environments
sub.check_call(" ".join(['conda','env','list','>','envs.txt']),shell=True)
# load and parse environment names
envs = pd.read_csv("envs.txt",header=1)
env_names = envs['#'].str.split(expand=True)[0]
# write environment packages out
for env in env_names:
print("Backing up...",env)
cmd = "conda env export --name %s > %s.yml" % (env,env)
sub.check_call(cmd,shell=True)
uninstall anaconda
rm -rf ~/anaconda3
conda uninstall
rm -rf ~/anaconda
- Edit
~/.bash_profile
and remove the anaconda directory from your PATH environment variable. - edit .bashrc or .profile or .bash_profile. Remove the following hidden files and directories in the home directory:
.condarc
and.conda
Create all envs from previous backded-up envs :
filenames=`ls *.yml`
for entry in $filenames; do
echo $entry
conda env create -f $entry
done
Note: sudo rm ./local/bin/jupyter*
When uninstalling and installing packages in the conda python environment, I encountered problem that the jupyter notebook cannot open and jupyter notebook is searching for previous conda env binarys.
This can be easily solved by editing the files in .local/bin (which is by default in the PATH variable to search for). In my case: in the .local/bin directory I find many jupyter ‘cache’ files that the first line is saying using previous conda python environment (not global python environment), Id deleted these files and it’s good!