Conda environment primer
conda vs mamba
mamba was created as a drop-in replacement for conda. It is a reimplementation of the
package manager in C++. An environment created with conda can be modified and activated
by mamba, and vice versa. Some slight differences exist on some commands, but all
the commands displayed here can be used by both.
Use either one you prefer.
Creating a new environment
By listing the packages
conda create --name <env_name> <pkg1> [<pkg2> [...]]
By using an environment file
conda create --name <env_name> -f <environment.yml>
What is the environment file?
The environment file is a YAML file that contains the list of packages to install in the environment. It can be used to create a new environment, or to update an existing one.
The environment file is named environment.yml by convention, but it can be named anything you want.
A basic environment file looks like this:
name: finesse3-env # name of the environment
channels: # channel to use
- conda-forge
dependencies: # What to install
- python=3.14
- finesse
- numpy
- pandas
- matplotlib
- jupyterlab
- pip
- pip: # installed by pip, not conda
- tqdm
Activating an environment
To be able to use an environment, it must first be activated. By activating it, conda will
modify the current terminal variables so that the executables and libraries from the environment are
available, and used instead of any system ones. For example, if git is available on your system but that
you also installed it in your environment, the one from the environment will be used after activation of the
environment.
conda activate <env_name>
Note
Commands targeting the active environment can also be executed without activating if by adding –name <env_name> to the command.
Deactivating an environment
conda deactivate
Deleting/removing an environment
conda env remove --name <env_name>
Executing a command
After activating an environment, all following commands executed inside this terminal will be executed within the environment.
You can also execute a command in an environment without activating it by using conda run:
conda run --name <env_name> <cmd>
Adding packages to an environment
conda add <pkg1> [<pkg2> [...]]
Updating an environment
Note
Updating an environment can lead to conflicts between packages (notably with pip packages). It is often simpler and cleaner to delete the environment and recreate it.
Update all packages
conda update --all
Update specific packages
conda update <pkg1> [<pkg2> [...]]
Install a specific version of packages
conda update "<pkg1>=<version>" [<pkg2>[=<version>] [...]]