Survive commands with Conda

Posted by Ghassan Karwchan on Wed, Dec 20, 2023

I had a previous post on how to setup virtual environments using pipevn, and virtualenv.
But Conda is more robust and useful, and now I am using it for all my projects.

Conda and the Shell

While you install Conda, it will ask you at the end if you want initialize conda from the shell environment.
The question is something like this:

1Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no] [no] >>>" Stack OverflowGitHub

If you answer yes, and you want to keep your shell clean, but you want to add temporarley Conda to your path, run this: Otherwise let’s talk about some useful command

 1# run this to initialize conda and activate base environment everytime
 2miniconda/bin/conda init
 3
 4# to just initialize conda but not the base environment then run this
 5conda config --set auto_activate_base false
 6
 7# to reverse the whole initialization and keep your shell clean then 
 8conda init --reverse $SHELL
 9
10# if you have nothing in your shell and you just want to initialize conda without base enviornment
11source miniconda3/etc/profile.d/conda.sh

Manage Conda environments

 1# to see all environments
 2conda info --envs
 3conda env list
 4
 5# to create an environment with paython version
 6conda create --name env-name python=3.9
 7
 8## to create an environment from an environment file
 9## --name is optional and can be set from the file
10conda create --file env-file.yml --name env-name
11
12
13## to update an environment from environment file
14## if the environment is alreeady activated, no need to set the name
15## prune if you want to remove some packages
16conda env update --file env-file.yml --name env-name --prune