Cookies on this website

We use cookies to ensure that we give you the best experience on our website. If you click 'Accept all cookies' we'll assume that you are happy to receive all cookies and you won't see this message again. If you click 'Reject all non-essential cookies' only necessary cookies providing core functionality such as security, network management, and accessibility will be enabled. Click 'Find out more' for information on how to change your cookie settings.

Instructions on how to use the Conda tool to build Python environments

Python versions
Python 2 is no longer supported and so all new software should be developed with Python 3. There may be some older software that still requires Python 2 - the information below provides details on how you might run this software.

Obtaining Python

The FMRIB SLURM cluster already has Miniforge and Miniconda available via environment modules, so these installation instructions are only relevant for your own laptop/desktop computer. To use 'conda' on the cluster, use:

module add Miniforge3

Whilst Linux and macOS ship with Python by default (often via the 'python3' command), the version provided isn't always the most up-to-date and installing additional packages may require administrative privileges.

We recommend using MiniForge (bare-bones package manager) or Miniconda/Anaconda (complete analysis environment). Choose Anaconda if you want to replicate a MATLAB environment as it includes all the common libraries by default - but be aware that this has a restrictive software license, which, depending on your use case, may make it unsuitable for use with your work - MiniForge has a completely open license. Miniconda/Anaconda requires a subscription to use in a commercial setting (it is free for academic use).

https://github.com/conda-forge/miniforge/releases

https://www.anaconda.com/products/distribution and https://docs.anaconda.com/free/miniconda/index.html

Once downloaded, run the install script and choose a location to install the conda tools too - the suggested defaults are recommended, e.g. installing conda into your home folder.

Once installed, it would be a good idea to immediately check you have the current release of the conda tool. Upgrade with the command: 

conda update --all

Environments 

Conda utilises environments to group together the libraries and tools necessary for a particular task enabling you to use the specific versions of libraries you need for your program without impacting other tools (which use a different environment or indeed python version). We recommend that you create your own environment for development work as that makes it very easy to determine which libraries you need if you are installing elsewhere or indeed distributing it to others as you can create manifest files that will replicate the environment easily.  

Creating environments

To create your own environment use:  

conda create --name=myenv python

This will create a bare-bones environment called myenv containing python 3.x and a few support tools. Add more python packages to the end if you know you need them immediately.

If you need to use python 2.x for the environment then use: 

conda create --name=myenv python=2

You can now activate this environment for use with: 

source activate myenv

At this point python is the version installed within the myenv environment. 

Installing packages

Conda usage instructions ] 

Conda has tools for installing packages via three methods: 

  1. Conda packages 
    • If you know the name of the package then:

      conda install PACKAGE

      If you are not sure of the name then use the conda search tool, e.g.

      conda search plot

      Will tell you that the package name you were probably after is matplotlib.

  2. Conda-Forge packages
    • https://conda-forge.org provides a community driven collection of Conda packages. This is the service that Miniforge gets all of its packages from. If Anaconda is lacking a package you require then, this is a good location to check.
      With Miniforge's conda you can simply use for example:

      conda install nibabel
      But with ana/miniconda you will need to specify that Conda-forge should be used:
      conda install -c conda-forge nibabel
  3. Pypi packages 
    • Pypi packages require the pip command which can be installed with (usually installed by default): 

      conda install pip

      Before falling back to Pypi.org for packages, check that they aren't available at Conda-forge:
      You can then install the package using: 

    • pip install package

      It is quite possible that you will need a C/C++/Fortran compiler to install packages via this method.