Skip to content

Python Software Installation: mamba or conda (Self-Installed)

Users can install their own distributions of the mamba and conda package managers to have additional flexibility with environments.

Please note: While the environment management software described in this page has permissive licenses and can be used for free, channels (sources of packages) may have other license terms and may require commercial licenses. It is your responsibility to use an appropriate channel.

On this page

The table of contents requires JavaScript to load.

Environment Management Tools

There are a variety of options for users to pick from when installing and maintaining their own software installations, both within and outside of Python. While there are pros and cons to each solution, which we have summarized below, the CHPC suggest the mamba tool through Miniforge for its light-weight installation, broad range of software support, and ease of use.

Miniforge/Mambaforge is a minimalistic Python packaging distribution which includes conda and mamba package managers and their dependencies. It is using the "conda-forge" package repository by default which means that it's free for research and teaching. Additional packages need to be installed manually. The base installation size is about 0.8 GB.

Micromambais a tiny version of the mamba package manager. It is a statically linked C++ executable with a separate command line interface. It does not need a base environment and does not come with a default version of Python. It is a good candidate for packaging the whole Python environment in a container, as described below.

Miniconda is a minimal Anaconda distribution that comes with base Python and the conda package manager. This makes the base installation rather small at 0.3 GB. Because it defaults to the "defaults" channel that has license restrictions, we discourage users from using miniconda.

Anaconda is the most popular Python distribution. It is well optimized and comes with Intel MKL for fast and threaded numerical calculations. It also comes with a package manager system, conda, and includes many commonly used Python packages. For this reason, it occupies 3.2 GB when installed, which is a sizeable amount given our default 50 GB home directory quota. For this reason it is not our top choice. Like Miniconda, its license has restrictions, which is why we recommend against using it.

Intel Distribution for Python is provided by Intel with performance similar to Anaconda. Also, similarly to Anaconda, it includes select numerical modules. It can be either installed as a standalone package or through the conda package manager. Recently, Intel contributions have been incorporated into the main package repositories which makes it unnecessary to have this installed separately.

Miniforge Installation and Usage

While the CHPC maintains their own modules, which you can view through the module spider command, users can also install and use their own modules within their home directories. Below, we will walk you through installing Miniforge as a module and utilizing that new module to install software.

Miniforge Installation

Download the Miniforge installer using the wget command and run the installer, pointing it to the directory where you want to install it. We recommend $HOME/software/pkg/miniforge for easy integration into user defined environment modules.

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
bash ./Miniforge3-Linux-x86_64.sh -s -b -p $HOME/software/pkg/miniforge3

The flag '-b' forces unattended installation, the '-p' flag marks the installation directory, and the -s flag prevents Miniforge from being added to your default environment. Miniforge will be added to your environment in the next step, via environment modules.

Upon successfully executing these commands above, you should see a new mamba binary file named located at  $HOME/software/pkg/miniforge/bin/mamba. Verify that this file exists.

Creating a Miniforge Module

To set up a Miniforge module, first create a directory where the module file will reside and then copy our miniconda module file to that directory:

mkdir -p $HOME/MyModules/miniforge3
cp /uufs/chpc.utah.edu/sys/installdir/python/modules/miniforge3/latest.lua $HOME/MyModules/miniforge3

If miniforge is installed in a different location than $HOME/software/pkg/miniforge , the module file should be edited to set the local mymambapath variable to the full path where this miniforge installation is.

To use the new module in your home directory, make the module accessible to your environment with the module use command. After that, we can load your new miniforge3 module:

module use $HOME/MyModules
module load miniforge3/latest

By using the module load command, you place Miniforge into your environment.

Do not run the conda init or mamba init commands, even though conda/mamba sometimes suggest this. These commands hardcode the Miniforge environment in your default environment, which is what we are trying to avoid by using the module setup.

To make your mamba installation and/or virtual environments available to be used by others, please look at the documentation here.

To make the user module environment available in all your future sessions, edit ~/.custom.csh (for tcsh shell) or ~/.custom.sh (for bash shell) and insert the module use command just below the #!/bin/tcsh or #/bin/bash. Do not put the module load miniforge3 command in these files since custom Python installations can break the remote connections using FastX.

Mamba Package Manager Basics

When installing software with mamba, there are two general methods that you could use: installing software to the mamba base environment or installing software to separate virtual environments. If you plan to use multiple packages that each require separate software dependencies, the CHPC recommendeds that you install each package into a separate virtual environment. If you plan to use virtual environments, do not install any additional packages into the base environment, as this may break the dependencies in the virtual environments.

To find common use cases outside of the scope of this documentation, take a look at the Conda cheat sheet. More detailed documentation is in the Mamba User Guide or Conda User Guide. Mamba is a drop in replacement for Conda, so Conda and Mamba syntax is the same.

Miniforge Virtual Environments

Because Miniforge supports virtual environments (venvs), one can leverage multiple environments from a single Miniforge module installation. We can list existing environments with:

mamba env list

Assuming one uses a bash shell, we can, for example, install the Intel distribution for Python into a separate environment:

mamba update -y mamba
mamba create -n py311 python=3.11

mamba update updates conda ("-y" answers "yes" to individual package updates automatically). The mamba create command, in conjunction with the -n flag, creates a new environment named py311, which includes Python 3.11.

We can then activate the environment as:

conda activate py311

NOTE: mamba activate does not work, use conda activate instead.

All conda package commands can be used within the activated environment, meaning additional conda packages can be installed in this environment using the mamba install command.

To exit from the environment, run:

conda deactivate

Similarly to mamba activate, mamba deactivate does not work.

To delete an environment, such as the idp3 environment we created above, you would run:

conda env remove --name py311

Installing Additional Packages with Mamba

This section includes instructions for installing additional software to your base Miniforge3 software installation installed via the commands above. The CHPC does not recommend users install additional software within the base Miniforge3 software installation as this can create software dependency conflicts. The solution to these conflicts is to install a fresh Miniforge3 environment and create a separate module file for each fresh install, however this takes up unneeded space in your home directory. We therefore would instead recommend creating mamba virtual environments.

Miniforge3 only comes with a basic Python distribution. Therefore, you need to install your additional Python modules to the base environment by hand. After following the instructions for installing and using the miniforge module above, you can list the currently installed Python modules as follows:

To install a new package, run

mamba install [packagename]

For example, to install the latest version of the SciPy module, run

mamba install scipy

The installer will think for a little while and then install SciPy and a number of other packages on which SciPy depends, such as NumPy and the accelerated OpenBLAS library.

To install a specific version of scipy, run:

mamba install scipy=1.14.1

To uninstall a package run

mamba uninstall [packagename]

NOTE: If you notice that the Intel Math Kernel Library (MKL) is installed instead, since the MKL library by defaults utilizes all the processor cores on the system, if you are planning to run many independent parallel Python calculations, set the environment variable OMP_NUM_THREADS=1 (setenv OMP_NUM_THREADS 1 for tcsh or export OMP_NUM_THREADS=1 for bash).

Conda Packages in other Channels

If the mamba install command cannot find the requested package, chances are that it will be in a non-default conda repository (also called a conda channel). Independent distributors can create their own package channels that house their software. The best approach to find a package that is not in an official conda channel is to do a websearch for it.

For example, to look for a package named Fasta, which is used for biological sequence alignment, we web search for "anaconda fasta". Top search hit suggests the following installation line:

mamba install -c biobuilds fasta

The "-c" option specifies the channel name, in our case biobuilds.

To add a channel to the default channel list, we can:

mamba config add channels biobuilds

However, this puts a channel at the top of the list, with the highest priority. We can add a new channel to the bottom of the list instead in the following way:

mamba config --append channels biobuilds

If you are using Anaconda or Miniconda, it is better to add the free conda-forge channel and remove the commercial defaults channel with the commands below. Although as of October 2024, Anaconda, Inc, which manages the defaults channel says that it is free for academic institutions, there have been some controversies around that.

conda config --add channels conda-forge
conda config --set channel_priority strict
conda config --remove channels defaults

To verify that the defaults channel is removed:

conda config --show channels
channels:
- bioconda
  - conda-forge
- r

Installing Python Modules with Pip

When a Python package does not exist as a conda package, one can use Python's pip installer. We recommend using pip only as a last resort because you lose the flexibility of the conda packaging environment, as conda works towards automatic conflict resolution between packages and version upgrade/downgrade).

To install a module using pip, we suggest you run:

pip install bibtexparser

Another install option includes:

python -m pip install bibtexparser

For additional methods of installing Python packages, see our older documentation.

Using Conda/Mamba Virtual Environments in Open OnDemand

Just as we can install software packages within mamba virtual environments, we can also install Jupyter notebook into a virtual environment to start up Jupyter notebook session. It is not recommended to run the Jupyter notebook command from the terminal, as it will require us to create an SSH tunnel to the machine where we run the terminal to access Jupyter in our client's web browser. The Open OnDemand Jupyter app simplifies this problem greatly by launching Jupyter directly in the client's browser.

We can begin this process by first following the mamba installation instructions above, then by creating a virtual environment and installing the software into it. In this example, we will install the software scipy into a Mamba virtual environment that we plan to use in a Jupyter notebook session.

module use $HOME/MyModules
module load miniforge3/latest
mamba update -y mamba
mamba create -n my_venv jupyterlab scipy
conda activate my_venv
pip install jupyter notebook
conda deactivate

The module commands above load the newly created miniforge module into our environment. In the 'mamba create' command, we name our virtual environment 'my_venv' and install the jupyterlab and scipy software. We then activate the virtual environment with conda, use pip to install jupyter notebook tools into the environment, and finish by deactivating the environment.

To use the virtual environment in Open OnDemand's Jupyter app, we choose the "Custom (Environment setup below)" option for the "Jupyter Python version", and in the "Environment Setup for Custom Python" text box, put:

module use $HOME/MyModules
module load miniforge3/latest
conda activate my_venv

Once your Jupyter session begins, you should now be able to successfully connect to a Jupyter notebook and access the commands within your virtual environment.

Setting up Miniforge for Others to Use

Sometimes a researcher needs to install a Miniforge package that they want their co-workers to use as well. This helps with reproducibility, as the same software stack is used by all the researchers. To achieve this, we follow the Miniforge installation and usage instructions, but with a few modifications outlined below.

First, we install Miniforge to a different location and change its name to the package that we want to install to easily recognize the environment. For example, if we plan to create a Miniforge environment with the BLAST+ bioinformatics package, we could name the directory miniconda3-blast.

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
bash ./Miniforge3-Linux-x86_64.sh -b -p $HOME/software/pkg/miniforge3-blast -s

Next, we create the module file. We should name it along the same lines as the package name; in this example it would be miniconda3-blast. We get the module template from CHPC as follows:

mkdir -p $HOME/MyModules/miniforge3
cp /uufs/chpc.utah.edu/sys/installdir/python/modules/miniforge3/latest.lua $HOME/MyModules/miniforge3/blast.lua

The template module file is the same as CHPC's template, so it only points to the miniforge in the owner's $HOME, and, in its current state, would be unable to be used by other users. As we want this miniforge environment to be available to other users, we need to modify the new module file to include the absolute path to the location of this new miniforge3-blast installation and not the local path based on your $HOME directory.

To change this, open the module file in a text editor and look at lines 25-30:

-- change myanapath if the installation is in a different place in your home
-- note that this is a relative path from the base of your home directory
local mymambapath = "software/pkg/miniforge3"
-- if you want to share this miniforge installation with others, use the full
-- path
--local mymambapath = "/uufs/chpc.utah.edu/common/home/u0123456/software/pkg/miniforge3"

Notice that the  mymambapath is a relative path, not an absolute one. The $HOME variable will be added to this relative path later in the module file. As each user has their own unique $HOME, this prevents other users from using this module file to set up this miniforge environment. To fix this, we have to put the absolute path to our new minforge in the mymambapath variable, as follows:

-- change myanapath if the installation is in a different place in your home
-- note that this is a relative path from the base of your home directory
-- local mymambapath = "software/pkg/miniforge3"
-- if you want to share this miniforge installation with others, use the full
-- path

local mymambapath = "/uufs/chpc.utah.edu/common/home/u0123456/software/pkg/miniforge3-blast"

Changing u0123456 to your uNID. Later in the module file, the logic recognizes this change in the local mymambaapath and keeps this absolute path.

Once we save the module file, we are ready to use it and initialize the miniconda environment:

module use $HOME/MyModules
module load miniforge3/blast

Other users can do the same, except that they have to use the full path to your home directory, again replacing u0123456 with your uNID:

module use /uufs/chpc.utah.edu/common/home/u0123456/MyModules
module load miniforge3/latest

Once the miniforge3/blast module is loaded, we can run the mamba  commands to install the needed packages, e.g. for BLAST:

mamba install -c bioconda blast

and then make it available to co-workers.

Please, note that we recommend not to install Conda or Python Virtual Environments (venvs) into a singular module-based Miniforge installation. A more robust approach is to create multiple Miniforge installations with corresponding module names. Within these separate Miniforges, install the packages that would otherwise be installed in the venvs. There are several advantages to this approach. First, the packages installed into the separate Miniforges are completely independent from each other, which alleviates possible dependency and versioning problems between the base Conda environment and the Virtual Environment. Second, the tcsh shell has been historically less supported with the venvs, creating problems for tcsh users. Finally, the modules can be freely loaded and unloaded, allowing to completely clear the environment, which is more problematic with the venvs, as there is always the base environment that remains.

Miniconda Installation Examples

Interactive Machine Learning Environment with Tensorflow, Keras and Jupyter Lab

Tensorflow is a widely used deep learning framework. Keras is an add-on to the framework that attempts to make it more user friendly. Jupyter Lab allows to run Jupyter notebooks, e.g. in our Open Ondemand web portal.

As Tensorflow performs best on GPUs, we will be installing the GPU version. Once Miniforge3 and its module are installed, look at the Tensorflow installation requirements to note the CUDA and CUDNN versions that the latest Tensorflow requires. As of this writing (September 2024), Tensorflow 2.5 requires CUDA 12.1 and CUDNN 8.9.

  • Load the CUDA and CUDNN modules, and the newly installed Miniconda module (named tf25.lua)
    module load cuda/12.1.0 
    module load cudnn/8.9.7.29-12-gpu
    module use $HOME/MyModules
    module load miniforge3/tf25
  • Install Jupyter Lab in a virtual environment and activate the virtual environment.
    mamba create -n my_venv jupyterlab
    conda activate my_venv
  • Install Tensorflow. Note that we are using pip, not conda, as Google provides its tensorflow builds in pip repositories and the conda repositories don't have all of the versions. This pip installed Tensorflow also includes Keras. Test that Tensorflow can access the GPU(s).
    pip install jupyter notebook
    pip install tensorflow
    python -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())"
    conda deactivate
  • In the OpenOnDemand Jupyter Lab app launch window, put the following in the Environment Setup:
    module load cuda/11.2
    module load cudnn/8.1.1
    module use $HOME/MyModules
    module load miniconda3/tf25
    conda activate my_venv
    Note that in order to use GPU with Tensorflow, you need to request a GPU in the 'Advanced options' checkbox.

Last Updated: 11/6/24