Conda
FIX: make general
Questions
What does Conda do?
How to create a Conda environment
Objectives
Learn pros and cons with Conda
Learn how to install packages and work with the Conda (isolated) environment
Install with conda (UPPMAX)
Note
We have mirrored all major conda repositories directly on UPPMAX, on both Rackham and Bianca. These are updated every third day. We have the following channels available:
bioconda
biocore
conda-forge
dranew
free
main
pro
qiime2
r
r2018.11
scilifelab-lts
You reach them all by loading the conda module. You don’t have to state the specific channel when using UPPMAX. Otherwise you do with conda -c <channel> ...
First steps
First load our conda module (there is no need to install you own miniconda, for instance)
module load conda
This grants you access to the latest version of Conda and all major repositories on all UPPMAX systems.
Check the text output as conda is loaded, especially the first time, see below
Conda load output
The variable CONDA_ENVS_PATH contains the location of your environments. Set it to your project’s environments folder if you have one.
Otherwise, the default is ~/.conda/envs.
You may run
source conda_init.shto initialise your shell to be able to runconda activateandconda deactivateetc.Just remember that this command adds stuff to your shell outside the scope of the module system.
REMEMBER TO
conda clean -aonce in a while to remove unused and unnecessary files
First time
The variable CONDA_ENVS_PATH contains the location of your environments. Set it to your project’s environments folder if you have one.
Otherwise, the default is ~/.conda/envs.
Example:
export CONDA_ENVS_PATH=/proj/snic2022-22-641/nobackup/<username>By choice
Run
source conda_init.shto initialise your shell (bash) to be able to runconda activateandconda deactivateetcetera instead ofsource activate. It will modify (append) your.bashrcfile.
Using Conda
Conda cheat sheet
List packages in present environment:
conda listList all environments:
conda info -eotconda env listInstall a package:
conda install somepackageInstall from certain channel (conda-forge):
conda install -c conda-forge somepackageInstall a specific version:
conda install somepackage=1.2.3Create a new environment:
conda create --name myenvironmentCreate a new environment from requirements.txt:
conda create --name myenvironment --file requirements.txtOn e.g. HPC systems where you don’t have write access to central installation directory:
conda create --prefix /some/path/to/envActivate a specific environment:
conda activate myenvironmentDeactivate current environment:
conda deactivateWhen conda is loaded you will by default be in the base environment, which works in the same way as other conda environments. include a Python installation and some core system libraries and dependencies of Conda. It is a “best practice” to avoid installing additional packages into your base software environment.
Create the conda environment
Example:
conda create --name python36-env python=3.6 numpy=1.13.1 matplotlib=2.2.2
mambais a fast drop-in alternative to conda, using “libsolv” for dependency resolution. It is available from thecondamodule.Example:
mamba create –name python37-env python=3.7 numpy=1.13.1 matplotlib=2.2.2
Activate the conda environment by:
source activate python36-env
You will see that your prompt is changing to start with
(python-36-env)to show that you are within an environment.
Now do your work!
Deactivate
conda deactivate
Warning
Conda is known to create many small files. Your diskspace is not only limited in GB, but also in number of files (typically
300000in $home).Check your disk usage and quota limit with
uquotaDo a
conda clean -aonce in a while to remove unused and unnecessary files
`More info about Conda on UPPMAX
<https://uppmax.uu.se/support/user-guides/conda-user-guide/>`_
Working with Conda environments defined by files
Create an environment based on dependencies given in an environment file
$ conda env create --file environment.yml
Create file from present conda environment:
$ conda env export > environment.yml
environments.yml (for conda) is a yaml-file which looks like this:
name: my-environment
channels:
- defaults
dependencies:
- numpy
- matplotlib
- pandas
- scipy
environments.yml with versions:
name: my-environment
channels:
- defaults
dependencies:
- python=3.7
- numpy=1.18.1
- matplotlib=3.1.3
- pandas=1.1.2
- scipy=1.6.2
More on dependencies
Keypoints
Conda is an installer of packages but also bigger toolkits
Conda creates isolated environments not clashing with other installations of python and other versions of packages
Conda environment requires that you install all packges needed by yourself. That is, you cannot load the python module and use the packages therein inside you Conda environment.