Advanced setup of MNE-Python¶

Using MNE-Python with IPython / Jupyter notebooks¶

When using MNE-Python within IPython or a Jupyter notebook, we strongly recommend using the Qt matplotlib backend for fast and correct rendering. On Linux, for example, Qt is the only matplotlib backend for which 3D rendering will work correctly. On macOS, certain matplotlib functions might not work as expected on backends other than Qt. Enabling Qt can be accomplished when starting IPython from a terminal:

$pip install --upgrade --no-deps https://github.com/mne-tools/mne-python/archive/master.zip  If you plan to contribute to MNE-Python, or just prefer to use git rather than pip to make frequent updates, check out the contributing guide. Using MNE-Python with other Python distributions¶ While the Anaconda Python distribution provides many conveniences, other distributions of Python should also work with MNE-Python. In particular, Miniconda is a lightweight alternative to Anaconda that is fully compatible; like Anaconda, Miniconda includes the conda command line tool for installing new packages and managing environments; unlike Anaconda, Miniconda starts off with a minimal set of around 30 packages instead of Anaconda’s hundreds. See the installation instructions for Miniconda for more info. It is also possible to use a system-level installation of Python (version 3.5 or higher) and use pip to install MNE-Python and its dependencies, using the provided requirements file: curl --remote-name https://raw.githubusercontent.com/mne-tools/mne-python/master/requirements.txt pip install --user requirements.txt  Other configurations will probably also work, but we may be unable to offer support if you encounter difficulties related to your particular Python installation choices. Using MNE-Python with CUDA (NVIDIA GPU acceleration)¶ Some operations in MNE-Python can utilize NVIDIA CUDA GPU processing to speed up some operations (e.g. FIR filtering) by roughly an order of magnitude. To use CUDA, first ensure that you are running the NVIDIA proprietary drivers on your operating system, and then do: $ conda install cupy
$MNE_USE_CUDA=true python -c "import mne; mne.cuda.init_cuda(verbose=True)" Enabling CUDA with 1.55 GB available memory  If you receive a message reporting the GPU’s available memory, CuPy is working properly. To permanently enable CUDA in MNE, you can do: >>> mne.utils.set_config('MNE_USE_CUDA', 'true')  You can then test MNE CUDA support by running the associated test: $ pytest mne/tests/test_filter.py -k cuda


If the tests pass, then CUDA should work in MNE. You can use CUDA in methods that state that they allow passing n_jobs='cuda', such as mne.io.Raw.filter() and mne.io.Raw.resample(), and they should run faster than the CPU-based multithreading such as n_jobs=8.

Off-screen rendering in MNE-Python on Linux with MESA¶

On remote systems, it might be possible to use MESA software rendering (such as llvmpipe or swr) for 3D visualization (with some tweaks). For example, on CentOS 7.5 you might be able to use an environment variable to force MESA to use modern OpenGL by using this before executing spyder or python:

$export MESA_GL_VERSION_OVERRIDE=3.3  Also, it’s possible that different software rending backends might perform better than others, such as using the llvmpipe backend rather than swr. MESA also can have trouble with full-screen antialiasing, which you can disable with: $ export MNE_3D_OPTION_ANTIALIAS=false


or by doing mne.viz.set_3d_options(antialias=False) within a given Python session.

Troubleshooting 3D plots in MNE-Python¶

3D plotting trouble after version 0.20 upgrade on macOS¶

When upgrading MNE-Python to version 0.20, some macOS users may end up with conflicting versions of some of the 3D plotting dependencies. If you plot using the pyvista 3D backend and find that you can click-drag to rotate the brain, but cannot adjust any of the settings sliders, it is likely that your versions of VTK and/or QT are incompatible. This series of commands should fix it:

$conda uninstall vtk$ pip uninstall -y pyvista
$conda install vtk$ pip install --no-cache pyvista


If you installed VTK using pip rather than conda, substitute the first line for pip uninstall -y vtk.

3D plotting trouble using mayavi 3D backend¶

If you run into trouble when visualizing source estimates (or anything else) using mayavi, you can try setting a couple of environment variables at the beginning of your script, session, or notebook:

>>> import os
>>> os.environ['ETS_TOOLKIT'] = 'qt4'
>>> os.environ['QT_API'] = 'pyqt5'


This will tell mayavi to use Qt backend with PyQt bindings, instead of the default PySide. For more information, see http://docs.enthought.com/mayavi/mayavi/building_applications.html#integrating-in-a-qt-application.