Conda / Mamba (C++ reimplementation of Conda) is a package manager and environment management system. Can be replaced by Pixi.
CLI interface docs: mamba docs
Packages: conda-forge docs
Installation¶
Miniforge¶
https://
bash Miniforge3-Linux-x86_64.shPrevent conda from activating the base env by default¶
conda config --set auto_activate_base falseCreate default environments¶
Jupyter Lab environment¶
conda create -n jupyter nb_conda_kernels jupyterlab jupyterlab-git ipywidgetsDefault data science environment¶
conda create -n default \
pandas polars geopandas statsmodels \
scikit-learn lightgbm xgboost catboost \
matplotlib seaborn plotly streamlit \
pydantic openpyxl fastexcel ipykernelWant to change kernel in jupyter?¶
Base environment needs the nb_conda_kernels package.
Every environment needs the ipykernel package.
conda install nb_conda_kernelsUpdating Conda¶
Update base environment¶
conda update condaUpdate all packages of activated environment¶
conda update --allEnvironments¶
Create new environment and switch to it¶
conda create -n name_of_new_env
conda activate name_of_new_envCreate environment with specific python version:
conda create -n name_of_new_env python=3.12Remove environment¶
conda deactivate # only relevant if environment to-be-deleted is activated
conda remove -n name_of_env --all
# alternative: conda env remove -n name_of_envList all environments¶
conda env listAdding channels to environment¶
Activate the environment, then:
conda config --env --add channels conda-forgeSharing an environment¶
This can be useful if you want to document the package versions for a project or if you are collaborating with other people so they can work with the same environment.
conda env export > environment.ymlTo exclude packages that were installed into the environment as a dependency add the flag --from-history.
This can help for cross-platform compatibility, because conda will figure out platform-specific dependencies.
However, this will not document the version of a package if the version was not explicitly stated when installing.
conda env export --from-history > environment.ymlTo recreate the environment using the yml file:
conda env create -f environment.ymlArchived¶
Deep learning environment¶
Prereq:
sudo apt-get install libhdf5-serial-dev # for saving keras models efficiently
sudo apt install graphvizconda create -n deeplearn
source activate deeplearn
conda install tensorflow-gpu
conda install matplotlib
conda install opencv # needed for some examples
conda install pydot # graphviz
conda install pillow # python imaging library
conda install cython # Why?
conda install ipykernel # for kernel selection in jupyter
# conda install matplotlib PyYAML opencv-python pydot pillow cythonCheck tensorflow gpu¶
import tensorflow as tf
tf.test.is_gpu_available(
cuda_only=False,
min_cuda_compute_capability=None
)