MNE-Python installation in windows does not work

Dear MNE forum,

I am trying for some time to install MNE-Python in a windows (version 10 - home) laptop without success.
Can you help me?

I have already an installation of anaconda and python that I had to use to other software.
Its is installed in “C:\Users\FML\anaconda3”.

So, I followed the instructions to install MNE-Python for “3D plotting and source analysis” which is in Installing MNE-Python — MNE 0.24.1 documentation.
I did all the commands in the anaconda command prompt as recommended.
When I launch spyder from the anaconda prompt, it opens a different spyder (5 instead of 4, my previous version), with the following error:
“link image0 hasn’t been detected!”

When I try to run inside spyder the following commands:
import os
import numpy as np
import mne

It gives an error:
File “C:\Users\FML.spyder-py3\temp.py”, line 9, in
import mne

ModuleNotFoundError: No module named ‘mne’

I tried to type conda activate mne, but then it goes to the mne environment, which does not recognize spyder. So, I runned the spyder in a base environment, and it still does not work.

How can I make MNE-python work in windows? I do not have other operating system available.
Can you please provide me a kind of installation instructions “for dummies”?
I must be making a mistake somewhere in the process.

I would be very grateful if you could help me on this subject.

Best wishes,

Sofia

:question: If you have a question or issue with MNE-Python, please include the following info:

  • MNE version: e.g. 0.24.0
  • operating system: e.g. macOS 12 / Windows 10 / Ubuntu 18.04

:page_facing_up: Please also provide relevant code snippets – ideally a minimal working example (MWE).

:fountain_pen: To get the correct formatting, paste your Python code, then select it, and click on the Preformatted text toolbar button.

:no_mobile_phones: Please avoid sharing screenshots of code and error messages! Screenshots are difficult to work with especially on mobile devices; they don’t allow others to copy code and other text; and they don’t show up in the search.

:point_right: :point_right: :point_right: Please edit or remove the above text before submitting your posting. :point_left: :point_left: :point_left:

@SRF Hi Sofia,
You can set the Python Interpreter in Spyder to the other environment, see this answer.

side request: Once you are able to do it please also check if you can restart the spyder console, for more details see this spyder issue. This is a problem I encountered recently with Spyder and would be interested to see if you could reproduce it. :slight_smile:

Hi,

I have already tried the options you send in the dialog and restarted the kernel without success.

Maybe I will try with jupyter, but I am really only starting in Python, I am not sure if the instructions given in the platform are complete. I think there are some basic steps that a proficient python user does that I am not doing. That is why I asked by a “dummies” manual.
One question nor clear to me is what steps to take in a normal command prompt and in the anacondas’s command prompt. Conda only works in the latter. Pip does not work at all, not even in windows.
My anaconda (anaconda3) was installed previously to work with a different software (https://simnibs.github.io/simnibs/build/html/index.htmlI, could this be the problem? Will I need to install another version of Python to make this work? How to avoid conflits with the simnibs software?

Thank you for your help.

Best,

Sofia

On windows, in a regular command prompt, pip works with py -m pip install ...
For your original problem, as described in the other answer, you have 2 separate environment: one where spyder is installed, one where MNE is installed. You need to tell Spyder to connect to the environment with MNE. This is what is described here: Frequently Asked Questions — Spyder 5 documentation

Could you detail how you do this step(s) and maybe we can find where you make a mistake?

Yes, I can.

I send you the detail of the procedures:

I already have anaconda installed with Jupyter_lab
I opened the anaconda prompt and, in the base environment, did the command

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

At first, it failed to create the environment, but then it solved it.

Because I want to use Jupyter, I did the command in the anaconda’s base environment

conda install --name base nb_conda_kernels

After this, I activated mne (in the anaconda prompt) at it shifted to mne environment

conda activate mne

Then I tested the intallation (inside mne environment in anaconda prompt)

python -c “import mne; mne.sys_info()”

It worked, with some faults:

C:\Users\FML\anaconda3\envs\mne\lib\site-packages\mne\utils\check.py:728: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if LooseVersion(version) >= LooseVersion(‘5.10’):
C:\Users\FML\anaconda3\envs\mne\lib\site-packages\mne\utils\check.py:728: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if LooseVersion(version) >= LooseVersion(‘5.10’):
Platform: Windows-10-10.0.19043-SP0
Python: 3.9.10 | packaged by conda-forge | (main, Jan 30 2022, 18:02:33) [MSC v.1929 64 bit (AMD64)]
Executable: C:\Users\FML\anaconda3\envs\mne\python.exe
CPU: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel: 12 cores
Memory: 15.9 GB

mne: 0.24.1
numpy: 1.22.1 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy: 1.7.3
matplotlib: 3.5.1 {backend=QtAgg}

sklearn: 1.0.2
numba: 0.53.1
nibabel: 3.2.1
nilearn: 0.9.0
dipy: 1.4.1
cupy: Not found
pandas: 1.4.0
mayavi: 4.7.2
pyvista: 0.33.2 {OpenGL 4.5.0 - Build 25.20.100.6446 via Intel(R) UHD Graphics 630}
pyvistaqt: 0.7.0
ipyvtklink: Not found
vtk: 9.0.3
PyQt5: 5.12.3
ipympl: Not found
mne_qt_browser: 0.1.7
pooch: v1.6.0

Then, I opened a new anaconda prompt and launched Jupyter-lab
(this did not work in the mne environment)

I was able to use mne in Jupyter lab, but I had to select mne in applications on the anaconda GUI first.

If I try with spyder, I have to lanch it in the anaconda prompt at base environment:

(base) C:\Users\FML>spyder
link image0 hasn’t been detected!

The sentence “link image0…” appears but spyder opens.

Then, I changed the environment in Tools > Preferences > Python interpreter, following the instructions in FAQ.

I restarted the kermel in “consoles” and try to run the instructions:

import os
import numpy as np
import mne

The following error appeared:

An error ocurred while starting the kernel
C:\Users\FML\anaconda3\envs\mne\python.exe: Error while finding module specification for ‘spyder_kernels.console’ (ModuleNotFoundError: No module named ‘spyder_kernels’)
I attach a PTRSCR to this message with the output in spyder.

While there is no solution, I will use JupyterLab with the anaconda navigator, it seems to be working fine.

I will keep you updated.

Thank you so much for your help!

Best,

Sofia

Ok, so for spyder it’s very simple to fix. You have to install spyder-kernels in the environment with MNE. Basically, Spyder is split into different modules, one for the editor and one for the console. You have correctly set the environment from Spyder to use the MNE environment; but it doesn’t find the required dependency in this environment, namely spyder-kernels.

1 Like

Just adding to the response by @mscheltienne, as I was fighting with similar problems recently: make sure that you install correct version of spyder-kernels, best from conda-forge channel. For example if you have Spyder 5.2.2 you should install in your mne environment:

conda install spyder-kernels=2.2.1 -c conda-forge

@mscheltienne Maybe we could improve the installation instructions in mne docs?

c.f. https://github.com/mne-tools/mne-python/pull/10300 to include spyder-kernels in the install description for spyder.