= Using MNE-Python from Brainstorm = ''Authors: Francois Tadel'' {{attachment:mne_logo.png||align="right",width="195px"}} [[https://mne.tools/|MNE-Python]] is an open-source software for processing neurophysiological signals written with the [[https://en.wikipedia.org/wiki/Python_(programming_language)|Python programming language]]. It provides an interesting 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 [[https://www.mathworks.com/help/matlab/call-python-libraries.html|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. For GUI users who are not very familiar with terminals and command-line operations, setting-up a Python environment with MNE-Python working might be a bit 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 so that we can improve it. <> == Installing Python == In order to use MNE-Python functions from Brainstorm you will need to: * use a version of MATLAB that supports the Python integration (>= 2016a), * install a Python environment on your computer (version 3.6 or higher), * install MNE-Python >= 0.21 in your Python environment, * configure Matlab and Brainstorm to connect to this Python environment. First you need to install Python and MNE-Python package on your computer. This is done independently from MATLAB. Follow the installation instructions from the MNE-Python website: https://mne.tools/stable/install/index.html == Installing MNE-Python == == Configuration in Brainstorm == In an ideal configuration, your Python environment is automatically detected and configured by Matlab, and you can use any process based on MNE-Python without any additional configuration. This might be the case on Linux or MacOS, but Windows computers always require some manual setup. Try to run a process using MNE-Python in Brainstorm. If it works, you can skip the rest of this section. Otherwise, follow the instructions below to locate the Python installation. ==== 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. {{attachment:anaconda_prompt.gif||width="498",height="166"}} 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 ==== * Install CPython 3.8: https://www.python.org/downloads/ * Let the installer add Python to the system PATH * Open a terminal: * pip install numpy==1.19.3 * Install compiled packages: * https://www.lfd.uci.edu/~gohlke/pythonlibs/#traits > traits‑6.1.1‑cp38‑cp38‑win_amd64.whl * pip install traits‑6.1.1‑cp38‑cp38‑win_amd64.whl * `pip install scipy matplotlib numba pandas xlrd scikit-learn h5py pillow statsmodels jupyter joblib psutil numexpr traits pyface traitsui imageio tqdm spyder-kernels mne imageio-ffmpeg vtk pyvista pyvistaqt mayavi PySurfer dipy nibabel nilearn neo python-picard PyQt5` == API description ==