Using Conda Environments
Create Environment
After loading a Miniconda module version for the first time and configuring your .condarc file, create a new conda environment named my_conda_env in your /projectnb space. We recommend use of the mamba command for superior speed than the traditional conda command when creating environments. Note that mamba and conda will create a completely empty environment, so we are installing Python version 3.10 in the example below.
[rcs@scc1 ~] module load miniconda
[rcs@scc1 ~] mamba create -y -n my_conda_env python=3.10
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
If you plan to use a Jupyter notebook or Jupyter LabĀ or Spyder for your code development, you need to install notebook, jupyterlab, or spyder packages, respectively:
[rcs@scc1 ~] module load miniconda
[rcs@scc1 ~] mamba create -y -n my_conda_env python=3.10 notebook
Activate Environment
Activate my_conda_env. Note that once activated, the command prompt begins with (my_conda_env) signifying you are inside the conda environment.
[rcs@scc1 ~] mamba activate my_conda_env
(my_conda_env) [rcs@scc1 ~]
Install Packages in Environment
To add packages released via conda channels, use mamba install. For packages released only though PyPI, use pip install.
Conda Packages
(my_conda_env) [rcs@scc1 ~] mamba install -y -c conda-forge spyder
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
In the above example, we installed Spyder from the conda-forge channel. There are many other conda channels such as bioconda, anaconda, or defaults.
PyPI Packages
(my_conda_env) [rcs@scc1 ~] pip install htseq
...
Installing collected packages: pysam, numpy, htseq
Successfully installed htseq-2.0.4 numpy-1.26.1 pysam-0.22.0
In the above example, we installed HTSeq into my_conda_env same as done within Python.
Installing and Distributing Conda Environments
Software are often distributed as conda environments through use of YAML configuration files.
Install from YAML
Here is an example of creating a conda environment from a YAML file. With the -n name argument an environment will be created in the location specified in your .condarc file. The -p /path/to/new/env flag can be used to place the environment in a specific location. The conda tool is recommended over mamba when exporting environments:
[rcs@scc1 ~] conda env create -n polymer_env -f environment.yml
In the above example, we installed Polymer from the distributed YAML file.
Export to YAML
Here is how you export an activated conda environment to a YAML format file:
(my_conda_env) [rcs@scc1 ~] conda env export -f environment.yml
This creates a YAML file with the conda and PyPI packages listed with the version and a build specification for each one. To export an environment with just the versions listed add the --no-builds flag. This can be helpful if you want to move an environment between operating systems, such as re-creating a conda enviroment from the SCC on a Mac OSX laptop:
(my_conda_env) [rcs@scc1 ~] mamba env export --no-builds -f environment.yml
Last updated: Loading…
