This post describes how to migrate conda environments. It is assumed that you have user-only conda and system-wide conda as described in the post.
- Save the full list of packages for all environments (except the base environment)
Check the existing environments.
conda info --envs
Save the list for each environment.
conda list -n <env-name> --explicit > <env-name>.spec
This is an example. $ is the command I typed and others are the output of the command.
$ conda info --envs
# conda environments:
#
base /home/hyonchoi/.miniconda3
py39-work * /home/hyonchoi/.miniconda3/envs/py39-work
$ conda list -n py39-work --explicit > py39-work.spec
- Comment out the conda-init lines in the
~/.bashrc
This is an example lines in the ~/.bashrc
. You can put # at the beginning of the line to comment out the line.
# # >>> conda initialize >>>
# # !! Contents within this block are managed by 'conda init' !!
# __conda_setup="$('/home/hyonchoi/.miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
# if [ $? -eq 0 ]; then
# eval "$__conda_setup"
# else
# if [ -f "/home/hyonchoi/.miniconda3/etc/profile.d/conda.sh" ]; then
# . "/home/hyonchoi/.miniconda3/etc/profile.d/conda.sh"
# else
# export PATH="/home/hyonchoi/.miniconda3/bin:$PATH"
# fi
# fi
# unset __conda_setup
# # <<< conda initialize <<<
- Launch a new shell and create environments
Launch a new shell or connect in a new terminal.
bash
For each saved list, create new environments with the same name.
conda create -n <env-name> --file <env-name>.spec