2. Installing MDAnalysis

Before you can start the tutorial, you need a working installation of MDAnalysis (with its test suite, MDAnalysisTests) on your Linux or Mac OS X machine. The following contains hints and links to further documentation to facilitate installation of the package.


For this tutorial, you will need at least version 0.18.0 of MDAnalysis.

2.1. Installation methods

For this tutorial you will install the latest release of MDAnalysis. We recommend the Conda installation method but the traditional Pip installation is also fully supported.

2.1.1. Conda installation

For this tutorial we recommend using the conda distribution. If you do not have conda installed, you can download the miniconda installer and install a small conda system, which will not interfere with other installed software. Follow the instructions for miniconda for your operating system.

The latest release of MDAnalysis (and the full test suite) can be installed from the conda-forge anaconda.org channel with conda

conda config --add channels conda-forge
conda update --yes conda

MDAnalysis fully supports Python 3.4+ and 2.7.x (since release 0.17.0). We will install a Python 3.6 environment that we call mdaenv:

conda create --yes -n mdaenv python=3.6

Install MDAnalysis and the tests including data files in the mdaenv environment:

conda install --yes -n mdaenv MDAnalysis MDAnalysisTests

Activate the installation (has to be done in every shell, whenever you want to use MDAnalysis):

source activate mdaenv

Check success 1:

(mdaenv) $ python -c 'import MDAnalysis as mda; print(mda.__version__)'

2.1.2. Pip installation


Installation with pip requires a working C-compiler on the system because some parts of MDAnalysis are compiled. If you don’t have a compiler toolchain configured, do the Conda installation.

The latest release of MDAnalysis (and the full test suite) can be installed from the python package index with pip

pip install --user MDAnalysis[analysis] MDAnalysisTests

(Installation of the test suite is required for this tutorial because we will use some of the data files that are part of the tests. The [analysis] tag installs additional packages that are used in specific analysis modules; although not used in this tutorial, it will make your MDAnalysis installation full-featured from the start.)

If there are problems then please have a closer look at the installation notes and the installation recipes; in particular, installing the netcdf library can become more involved.

If you need help with installation issues, please do not hesitate to ask on the user discussion group.

2.2. Testing the installation

MDAnalysis comes with over 6500 test cases that check its functionality. These test cases can be run with the command

pytest --disable-pytest-warnings --pyargs MDAnalysisTests

This can take 20 minutes, so run it when you have spare time (or see test cases for how to run the tests in parallel if you have multiple cores).

You should only get passing tests (“ok” or just a single dot “.”) or “KnownFailures”: look for a line such as

==== 6454 passed, 66 skipped, 1 xfailed, 21956 warnings in 1184.44 seconds =====

which indicates that everything works as expected.



In the following, the shell’s prompt is shown as (mdaenv) $ and should not be typed. It is supposed to remind you that you must be in the virtual environment 2. Only type what follows after the prompt. If the commands give any output, it is shown on the lines following the input.


Do not forget to activate the mdaenv environment whenever you open a new terminal:

source activate mdaenv

Otherwise, you will probably find that scripts cannot find MDAnalysis.

If you want to use ipython (see Python interpreter: ipython) or jupyter notebook then you must install ipython and jupyter into the same virtual environment as MDAnalysis or they might not properly find other installed libraries such as MDAnalysis.