Conda and mamba¶
Description¶
Conda and mamba are open source package manager and environment management systems for Python and other languages. They run on Windows, macOS, Linux and z/OS. These tools automate the process of installing, updating, configuring and removing software packages. They manage dependencies, ensuring that all required libraries and components are correctly installed and compatible. In our case, using package managers is specially useful because:
- They provide a way to ensure reproducibility in our code
- They allow a project's software tools to be portable
- They allow user-level installation (i.e. do not require sudo permissions)
The difference between the two is that mamba is a fast, drop-in replacement for conda that highly improves package resolution speed and efficiency (and we recommend you use it instead of conda to make your life happier :)).
Info
The majority of the commands shown below are also supported by mamba
Installation¶
Conda¶
Conda has two possible installers: - Anaconda: already comes with installed packages for data science and Anaconda Navigator (GUI application). Follow the instructions. - Miniconda (recommended): minimal installer provided by Anaconda
Download any of the two installers and in your terminal run:
Detailed instructions here. To update conda, run:
Mamba¶
The installer for mamba is micromamba. To install it run:
To update mamba:Get started¶
conda create -n <env name> <package[=<version>]>
conda activate <env name>
conda install <package[=version]>
Cheatsheet¶
Environments¶
Activate an environment:
Deactivates an environment. If in base
, closes conda.
List all environments:
Create a new virtual environment with
Export active environment to a file
Export all environments to its own file:
for env in $(conda env list | cut -d" " -f1); do
if [[ ${env:0:1} == "#" ]] ; then continue; fi;
conda env export -n $env > ${env}.yml
done
Create environment from file
Clone an environment
Remove an environment
List all packages installed (in current environment)
List all packages installed with path
Show history of changes in packages
Packages¶
Install a package (use -f
to force the installation)
Install package(s) specified in a file (like a Python requirements file)
Uninstall a package
Search for a package
Configuration¶
Show configuration
Add channels (use add
instead of append
to put the channel on the top of the list)
Building Packages¶
Install conda build
Build package
Build for other platforms
Install built package
From Pypi¶
Create files
Build for different Python version
Custom Channel¶
Add channel
(re)build the index
Reference¶
- Jordi Deu Pons
- Miguel Grau
- Federica Brando
- Carlos López-Elorduy
- Raquel Blanco