Skip to content
hero
Philippe Bordron

Create a conda environment

Load the conda module

The software conda is installed into the module Miniforge3. We must load it before to use it.

module load devel/Miniforge/Miniforge3

Create a conda environment

An environment allows to install a set of softwares and libraries without interfering with the rest of the system.

Which packages can be installed?

The website https://anaconda.org can be used to search available packages. The search can also be performed using the following command:

conda search <pkg-name>

How to create an environment?

The command conda create is designed for this purpose:

conda create -p </path/to/my/env> <pkg1> <pkg2>

This command will create an environment at the path </path/to/my/env> in which <pkg1> and <pkg2> will be installed.

Example

We want to create an environment compare-align where blast+ and diamond will be installed. This environment will be created into the directory ~/work/my-project/envs/

conda create -p ~/work/my-project/envs/compare-align blast diamondChannels:
- conda-forge
- bioconda
- nodefaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
...

We check that the enviromnent is created in the right place:

conda env list# conda environments:#
...
base /usr/local/bioinfo/src/Miniforge/Miniforge3
...
/work/<username>/my-project/envs/compare-align
...
Alternative

It is possible to replace the option -p by -n.

conda create -n <env-name> <pkg1> <pkg2>

In this case, the environment will be created at ~/.conda/envs/<env-name>.

Example

We create again a environment name compare-align:

conda create -n compare-align blast diamond...

We check the place where the environment was created:

conda env list# conda environments:#
...
compare-align /home/<username>/.conda/envs/compare-align
...
base /usr/local/bioinfo/src/Miniforge/Miniforge3
...

How to install a precise version of a software?

You can use notations =, ==, !=, <=, <, >= and > in order to target package versions.

Examples

  • Create an environment containing R version 3.6.x:

    # We create the env\(">conda create -p ~/work/envs/R-3.6 "r-base=3.6"</span><span data-ty>...</span><span class="termynal-comment" data-ty># We check which R is installed</span><span data-ty="input" data-ty-prompt="\)">source activate ~/work/envs/R-3.6conda list# packages in environment at /home/<username>/work/envs/R-3.6:# # Name Version Build Channel...
    r-base 3.6.3 hbcea092_8 conda-forge
    ...

  • Create an environment with last python 2 version and numpy:

    # We want the last version before python 3# but also something after python 2.6 (i.e. python 2.7.y)\(">conda create -p ~/work/envs/python-2.7 "python>2.6,<3" numpy</span><span data-ty>...</span><span class="termynal-comment" data-ty># We check which python version is installed</span><span data-ty="input" data-ty-prompt="\)">source activate ~/work/envs/python-2.7conda list# packages in environment at /home/<username>/work/envs/python-2.7:# # Name Version Build Channel...
    python 2.7.15 h5a48372_1011_cpython conda-forge
    ...

Escape characters

Make sure to use " when using > et <.

How to use a specific channel?

Sometime, a package is available in a channel you haven't configured. You can use the option -c or --channel to install it without altering your conda configuration.

Conda install

This option can also be used with the conda install command.

conda create -p <env> -c <channel1> -c <channel2> \ <pkg1> <pkg2> ...

Example

Install DESeq2 from bioconda channel and R, which is a dependency, from conda-forge channel.

conda create -p ~/work/envs/DESeq2 \ -c conda-forge -c bioconda bioconductor-deseq2

Channel priority

The further to the left of the command the channel appears, the lower its priority: conda-forge channel has priority over bioconda if a package exists in both channels.