Skip to content

Latest commit

 

History

History
263 lines (198 loc) · 10.7 KB

File metadata and controls

263 lines (198 loc) · 10.7 KB

Installing MNE-Python

Once you have Python/Anaconda installed, you have a few choices for how to install MNE-Python.

2D plotting and sensor-level analysis

If you only need 2D plotting capabilities with MNE-Python (i.e., most EEG/ERP or other sensor-level analyses), you can install all you need by running pip install mne in a terminal window (on Windows, use the "Anaconda Prompt" from the Start menu, or the "CMD.exe prompt" from within the Anaconda Navigator GUI). This will install MNE-Python into the "base" conda environment, which should be active by default and should already have the necessary dependencies (numpy, scipy, and matplotlib).

A second option is to install MNE-Python into its own virtual environment (instead of installing into conda's "base" environment). This can be done via:

$ conda create --name=new_environment_name python=3
$ conda activate new_environment_name
$ pip install mne

This approach is a good choice if you want to keep a separate virtual environment for each project. This helps with reproducibility, since each project-specific environment will have a record of which versions of the various software packages are installed in it (accessible with conda list).

3D plotting and source analysis

If you need MNE-Python's 3D rendering capabilities (e.g., plotting estimated source activity on a cortical surface) it is best to install MNE-Python into its own virtual environment, so that the extra dependencies needed for 3D plotting stay in sync (i.e., they only get updated to versions that are compatible with MNE-Python). See the detailed instructions below for your operating system.

.. collapse:: |linux| Linux

   Install MNE-Python from conda-forge::

       $ conda create --name=mne --channel=conda-forge mne

   .. collapse:: |hand-paper| If you get errors building mayavi...
       :class: danger

       Installing `mayavi`_ needs OpenGL support. On debian-like systems this
       means installing ``libopengl0``, i.e., ``sudo apt install libopengl0``.
.. collapse:: |apple| macOS

    Install MNE-Python into a new environment (here called ``mne``, but you can
    name the environment whatever you want)::

        $ conda create --name=mne --channel=conda-forge mne

    If you like using Jupyter notebooks, you should also update the "base"
    conda environment to include the ``nb_conda_kernels`` package; this will
    make it easier to use MNE-Python in Jupyter Notebooks launched from the
    Anaconda GUI::

        $ conda install --name=base nb_conda_kernels
.. collapse:: |windows| Windows

    Open an Anaconda command prompt, and run:

    .. code-block:: doscon

        > conda create --name=mne --channel=conda-forge mne

    If you like using Jupyter notebooks, you should also update the "base"
    conda environment to include the ``nb_conda_kernels`` package; this will
    make it easier to use MNE-Python in Jupyter Notebooks launched from the
    Anaconda GUI:

    .. code-block:: doscon

        > conda install --name base nb_conda_kernels

Installing to a headless server

.. collapse:: |server| If you are installing on a headless server...
    :class: danger

    With `pyvista`_:
    Download the `server environment file`_ and use it to create the conda
    environment::

        $ curl --remote-name https://raw.githubusercontent.com/mne-tools/mne-python/main/server_environment.yml
        $ conda create --name=mne --file=server_environment.yml

    With `mayavi`_:
    Installing `mayavi`_ requires a running `X server`_. If you are installing
    MNE-Python into a computer with no display connected to it, you can try
    downloading the :file:`environment.yml` file and removing `mayavi`_ from it
    before running :samp:`conda create --name mne --file environment.yml`, then
    activating the new environment, and then installing `mayavi`_ using `xvfb`_
    (e.g., :samp:`xvfb-run pip install mayavi`). Be sure to read Mayavi's
    instructions on `off-screen rendering`_ and `rendering with a virtual
    framebuffer`_.

    Note: if :samp:`xvfb` is not already installed on your server, you will
    need administrator privileges to install it.

Testing your installation

To make sure MNE-Python installed itself and its dependencies correctly, type the following command in a terminal:

$ python -c "import mne; mne.sys_info()"

This should display some system information along with the versions of MNE-Python and its dependencies. Typical output looks like this:

Platform:      Linux-5.0.0-1031-gcp-x86_64-with-glibc2.2.5
Python:        3.8.1 (default, Dec 20 2019, 10:06:11)  [GCC 7.4.0]
Executable:    /home/travis/virtualenv/python3.8.1/bin/python
CPU:           x86_64: 2 cores
Memory:        7.8 GB

mne:           0.21.dev0
numpy:         1.19.0.dev0+8dfaa4a {blas=openblas, lapack=openblas}
scipy:         1.5.0.dev0+f614064
matplotlib:    3.2.1 {backend=Qt5Agg}

sklearn:       0.22.2.post1
numba:         0.49.0
nibabel:       3.1.0
cupy:          Not found
pandas:        1.0.3
dipy:          1.1.1
mayavi:        4.7.2.dev0
pyvista:       0.25.2 {pyvistaqt=0.1.0}
vtk:           9.0.0
PyQt5:         5.14.1
.. collapse:: |hand-paper| If you get an error...
    :class: danger

    .. rubric:: If you see an error like:

    ::

        Traceback (most recent call last):
          File "<string>", line 1, in <module>
        ModuleNotFoundError: No module named 'mne'

    This suggests that your environment containing MNE-Python is not active.
    If you followed the setup for 3D plotting/source analysis (i.e., you
    installed to a new ``mne`` environment instead of the ``base`` environment)
    try running ``conda activate mne`` first, and try again. If this works,
    you might want to set your terminal to automatically activate the
    ``mne`` environment each time you open a terminal::

        $ echo conda activate mne >> ~/.bashrc    # for bash shells
        $ echo conda activate mne >> ~/.zprofile  # for zsh shells

If something else went wrong during installation and you can't figure it out, check out the :doc:`advanced` page to see if your problem is discussed there. If not, the `MNE Forum`_ is a good resources for troubleshooting installation problems.

Python IDEs

Most users find it convenient to write and run their code in an Integrated Development Environment (IDE). Some popular choices for scientific Python development are:

  • Spyder is a free and open-source IDE developed by and for scientists who use Python. It is included by default in the base environment when you install Anaconda, and can be started from a terminal with the command spyder (or on Windows or macOS, launched from the Anaconda Navigator GUI). If you use Spyder, you should not install it into the mne environment; instead, launch Spyder from the base environment and set it to use the mne environment automatically, by opening Spyder and navigating to :samp:`Tools > Preferences > Python Interpreter > Use the following interpreter`. There, paste the output of the following terminal commands:

    $ conda activate mne
    $ python -c "import sys; print(sys.executable)"

    It should be something like C:\Users\user\anaconda3\envs\mne\python.exe (Windows) or /Users/user/opt/anaconda3/envs/mne/bin/python (macOS).

  • Visual Studio Code (often shortened to "VS Code" or "vscode") is a development-focused text editor that supports many programming languages in addition to Python, includes an integrated terminal console, and has a rich ecosystem of packages to extend its capabilities. Installing Microsoft's Python Extension is enough to get most Python users up and running. VS Code is free and open-source.

  • Atom is a text editor similar to vscode, with a package ecosystem that includes a Python IDE package as well as several packages for integrated terminals. Atom is free and open-source.

  • SublimeText is a general-purpose text editor that is fast and lightweight, and also has a rich package ecosystem. There is a package called Terminus that provides an integrated terminal console, and a (confusingly named) package called "anaconda" (found here) that provides many Python-specific features. SublimeText is free (closed-source shareware).

  • PyCharm is an IDE specifically for Python development that provides an all-in-one installation (no extension packages needed). PyCharm comes in a free "community" edition and a paid "professional" edition, and is closed-source.