Using MNE-Python from Brainstorm

Authors: Francois Tadel

mne_logo.png MNE-Python is an open-source software for processing neurophysiological signals written with the Python programming language. It provides a rich library of methods that are not available in Brainstorm, especially for MEG signal pre-processing, statistics and machine learning. Since MATLAB now offers a very efficient interface with Python environments, it makes more sense to use directly the MNE-Python code rather than trying to recode its original features in MATLAB scripts. This tutorial will teach you how to set up MNE-Python for using it within MATLAB/Brainstorm.

For GUI users who are not familiar with terminals and command-line operations, setting-up a Python environment with MNE-Python might be challenging. The programs involved here are subject to frequent changes, we will most likely need to update this page regularly. If the documentation below is incomplete or incorrect, please share your comments on the user forum.

Requirements

The Python integration in MATLAB is recent has been changing a lot over the years. Only a limited number of Python distributions are supported in MATLAB, you need to make sure you are using versions of MATLAB, Python and MNE-Python that are compatible.

The reference version used to write this documentation is MNE-Python 0.21, which requires Python >= 3.6. The oldest version of MATLAB supporting Python 3.6 is Matlab 2017b. If you are using versions of Matlab older than this, consider using the compiled version of Brainstorm, based on Matlab 2020a, which supports recent Python integrations.

Installing Python and MNE-Python

In order to call MNE-Python functions from MATLAB or Brainstorm, you need to install a Python environment on your computer (version 3.6). The MNE-Python installation page recommends using the Anaconda distribution, which is unfortunately not officially supported by MATLAB.

The MATLAB-Python integration is only supported for CPython, the reference implementation of the Python programming language. Using other Python distributions is possible, but may take a lot of extra manual configuration work, and would break often with new software updates. Therefore we strongly recommend you use CPython instead of Anaconda.

Windows 10

Install Python:

Install MNE-Python:

Troubleshooting: Error mentioning Microsoft Visual Studio:

Troubleshooting: Error mentioning a bug in numpy:

Test the MNE-Python installation with the following command:

Configure MATLAB

Anaconda environments

If you installed MNE-Python in a dedicated environment using conda, the most reliable way to get everything to work is to start MATLAB from the Anaconda prompt, with the correct environment activated.

anaconda_prompt.gif

However, this is not the most convenient solution for Windows computers, where you would just like to click on the Matlab icon. Try with the other solutions first and get back to this one if you can't get it to work in other ways.

Locate the Python executable

asks you where is your Python executable located on your hard drive, and

pyversion('C:\Users\franc\Anaconda3\envs\mne\python.exe');

Windows

API description

MnePython (last edited 2020-11-06 16:27:38 by FrancoisTadel)