Instructions on how to use the Conda tool to build Python environments
Python versionsThere are two major releases of Python, 2.x and 3.x which are not always code compatible. Python 2 is no longer supported and so any new software should be developed against 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.
Whilst Linux and OS X ship with Python by default, 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 Anaconda (complete analysis environment). Choose Anaconda if you want to replicate a MATLAB environment as it includes all the common libraries by default. MiniForge has a completely open license, but Anaconda requires a subscription to use in a commercial setting (it is free for academic use).
https://github.com/conda-forge/miniforge/releases - there are two packages here - Miniforge (traditional, pure python) and Mambaforge (faster to install packages, but less tested). In most instances Miniforge is currently the recommended option.
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
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.
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.
(Ana/Mini)conda has tools for installing packages via three methods:
- 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.
- 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. To install one of these packages you need to activate the condo-forge repository in the install command.
conda install -c -c conda-forge nibabel
- 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.