# Problems running mne.viz.plot\_alignment() from within Spyder

**URL:** <https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274>\
**Category:** Support & Discussions\
**Tags:** visualization, installation\
**Created:** [June 15, 2021, 10:27pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274 "2021-06-15T22:27:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [June 15, 2021, 10:27pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/1 "2021-06-15T22:27:53Z")

</div>

After reading [this thread](https://mne.discourse.group/t/why-does-using-a-different-ide-affect-my-raw-plot/2770) I’m checking whether there’s been any developments on this topic, specifically for linux platform? I’m trying to use `mne.viz.plot_alignment` (which doesn’t have “block=” argument). The only way I’ve found to keep the plot window open is to execute the statement in a VSCode Jupyter notebook. Does anyone know whether other IDEs have yet recovered the previous Spyder capabilities? Or whether Spyder will ever work again with MNE?

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 15, 2021, 10:46pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/2 "2021-06-15T22:46:01Z")

</div>

@pettetmw I am able to run this in Spyder’s interactive console on Linux, and then interact with the figure (which stays popped open):

```python
import os.path as op
import mne
data_path = mne.datasets.sample.data_path()
subjects_dir = op.join(data_path, 'subjects')
raw_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif')
trans_fname = op.join(data_path, 'MEG', 'sample',
                      'sample_audvis_raw-trans.fif')
raw = mne.io.read_raw_fif(raw_fname)
trans = mne.read_trans(trans_fname)
src = mne.read_source_spaces(op.join(subjects_dir, 'sample', 'bem',
                                     'sample-oct-6-src.fif'))

fig = mne.viz.plot_alignment(raw.info, trans=trans, subject='sample',
                             subjects_dir=subjects_dir, surfaces='head-dense',
                             show_axes=True, dig=True, eeg=[], meg='sensors',
                             coord_frame='meg', mri_fiducials='estimated')

```

It also works if I click “run file” in spyder. Does that not work for you?

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [June 15, 2021, 11:48pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/3 "2021-06-15T23:48:07Z")

</div>

Works until call to plot\_alignment(), which throws the following:  
RuntimeError: Could not load any valid 3D backend: pyvista, mayavi, notebook

This is what I saw before. It seems that spyder, when invoked from conda “base”, isn’t fully utilizing my conda mne environment, even though I’ve set spyder preferences to use the mne python interpreter (as per mne installation instructions). I know that my mne environment definitely has all three backends installed, which is why I can get the figure to work correctly in VSCode Jupyter notebook. But, if I slip a mne.sys\_info() call into the script when running in spyder, it reports my python executable is still set to base environment, not mne, and none of the backends are installed.

I’d love to get spyder working again. VSCode isn’t doing it for me.

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 16, 2021, 2:46pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/4 "2021-06-16T14:46:02Z")

</div>

@pettetmw first thing I would do is remove MNE-Python from your `base` environment, if that is feasible given your workflows. Having MNE-Python installed in both `base` and `mne` envs is a recipe for confusion in my opinion.

Next thing I would do is `conda update -n base spyder`, and `conda update -n mne spyder-kernels`. Then I’d open spyder and re-do the step where you set the executable. Hopefully that sorts it.

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [July 3, 2021, 4:23pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/5 "2021-07-03T16:23:56Z")

</div>

OK, I did all that, but still stuck, here’s the relevant info (fyi, my mne environment is named “mne23”):

(base) mpettet@aloha:/mnt/ilabs/GITHUB$ pip show spyder-kernels  
Name: spyder-kernels Version: 1.9.4  
(mne23) mpettet@aloha:/mnt/ilabs/GITHUB$ pip show spyder-kernels  
Name: spyder-kernels Version: 2.0.3  
(mne23) mpettet@aloha:/mnt/ilabs/GITHUB$ python -c “import sys; print(sys.executable)”  
/home/mpettet/anaconda3/envs/mne23/bin/python  
(base) mpettet@aloha:/mnt/ilabs/GITHUB$ spyder &

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/810599454dc7360deddfd2fde364f11c64fd7970.png)

It looks like things should work as you describe, but now I can’t even get a console to launch. Perhaps “base” environment is messed up. How would I recreate that? Would I need to uninstall then reinstall conda itself?

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [July 9, 2021, 3:48pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/6 "2021-07-09T15:48:34Z")

</div>

The error message says that you don’t have the right version of spyder-kernels. It wants between 1.9.4 and 1.10, and (here is the crucial part that they don’t clearly express) that requirement is for the _mne23_ environment, not _base_. As your console output shows, in the mne23 environment you have spyder-kernels version 2.0.3

To reiterate, the key version compatibility is between `spyder` in _base_ and `spyder-kernels` in _mne23_.

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [July 12, 2021, 5:26pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/7 "2021-07-12T17:26:57Z")

</div>

I agree about incompatibility. The problem (I think) is that the `conda update -n mne23 spyder-kernels` command doesn’t seem to have the desired effect:

```python
(base) cd /mnt/ilabs/GITHUB/
(base) conda remove --name mne23 --all
(base) conda env update --file environment.yml --name mne23
Downloading and Extracting Packages
...
spyder-kernels-2.0.5 | 99 KB | #######...##### | 100% 
...
(base) conda activate mne23
(mne23) pip show spyder-kernels
Name: spyder-kernels
Version: 2.0.5
...
(base) conda deactivate
(base) conda update -n mne23 spyder-kernels
The following packages will be downloaded:

    package | build
    ---------------------------|-----------------
...
    spyder-kernels-2.0.5 | py39h06a4308_0 99 KB
...
The following packages will be SUPERSEDED by a higher-priority channel:
...
  spyder-kernels conda-forge::spyder-kernels-2.0.5-py3~ --> pkgs/main::spyder-kernels-2.0.5-py39h06a4308_0
...
(base) conda activate mne23
(mne23) pip show spyder-kernels
Name: spyder-kernels
Version: 2.0.5

```

How do I force `conda update` to downgrade to a specified version, and how do I specify that version? I tried tacking on the version number to the following command, which didn’t work:

```python
(base) mpettet@aloha:/mnt/ilabs/GITHUB$ conda update -n mne23 spyder-kernels-1.9.4

PackageNotInstalledError: Package is not installed in prefix.
  prefix: /home/mpettet/anaconda3/envs/mne23
  package name: spyder-kernels-1.9.4

```

`conda update --help` wasn’t too helpful for me, but might be for someone more familiar with it.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 16, 2021, 10:47am UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/8 "2021-07-16T10:47:33Z")

</div>

> [@pettetmw](#):
>
> The problem (I think) is that the `conda update -n mne23 spyder-kernels` command doesn’t seem to have the desired effect:

You need `spyder-kernels` from `conda-forge`; could you try:

```python
 conda update -c conda-forge -n mne23 spyder-kernels

```

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [July 19, 2021, 7:56pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/9 "2021-07-19T19:56:02Z")

</div>

No luck… same result as before (spyder throws error while starting mne23 kernel, which is still 2.0.5), except that `conda update -c conda-forge` no longer reports that it is downloading spyder-kernels. The message still appears about spyder-kernels version being `SUPERSEDED` by itself (which seems to be not what we want). Please also note that my previous error posting suggests that spyder kernels were already being obtained from `conda-forge`. Is there another channel, or a way to specify version?

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 20, 2021, 7:23am UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/10 "2021-07-20T07:23:33Z")

</div>

I would assume that there is something inconsistent about your `mne23` environment. Can you try to re-create it from scratch, following our installation instructions?

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [July 20, 2021, 4:19pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/11 "2021-07-20T16:19:29Z")

</div>

Do you think I should go so far as to name the environment “mne” instead of “mne23”? It seems like an unlikely explanation, but it is an inconsistency.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 20, 2021, 4:40pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/12 "2021-07-20T16:40:13Z")

</div>

Hello, no, the name of the environment should not have any influence. I only meant to suggest that you should try to re-create your environment – I’ve got the feeling that something is “off” with your current environment.

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [July 20, 2021, 8:19pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/13 "2021-07-20T20:19:43Z")

</div>

I had trouble with removing and re-installing mne, so I removed and re-installed anaconda too. This resulted in a more normal looking mne install, but the end result is still the same. Here’s my bash history:

```python
conda remove --name mne23 --all
conda deactivate
rm -rf ~/anaconda3/
bash ~/Downloads/Anaconda3-2021.05-Linux-x86_64.sh
# restart terminal
cd /mnt/ilabs/GITHUB/ # the location of my downloaded environment.yml file
(base) conda env update --file environment.yml --name mne23
(base) conda update -c conda-forge -n mne23 spyder-kernels

```

After this, I launched spyder from (base) and changed console settings to use /home/mpettet/anaconda3/envs/mne23/bin/python, as instructed, then quit and relaunched spyder. I still get the same spyder-kernels version error as my previous posting.

One other odd thing… possibly irrelevant: I noticed, when I went to configure the spyder console settings, that the path to `mne23/bin/python` was already filled into the edit box in the settings dialog. I’m going to try running `anaconda-clean` next. Stay tuned.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 20, 2021, 10:37pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/14 "2021-07-20T22:37:53Z")

</div>

Thanks for your effort and always reporting back, @pettetmw!

Say, would you be willing to try out a (preliminary) MNE installer? I’ve been working on something there to help reduce to number of problems some users are running into trying to get MNE-Python to work. Let me know if you’re interested and I can share something with you.

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [July 20, 2021, 11:30pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/15 "2021-07-20T23:30:10Z")

</div>

No problem. I’ll need a bit of downtime to catch up on some other tasks, but I can try installer when I’m back on this project next week. -Mark

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 29, 2021, 8:35am UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/16 "2021-07-29T08:35:59Z")

</div>

There’s now a pre-release available from [Release v2021.1-pre.3 · hoechenberger/mne-installers · GitHub](https://github.com/hoechenberger/mne-installers/releases/tag/v2021.1-pre.3)

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [July 29, 2021, 2:03pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/17 "2021-07-29T14:03:41Z")

</div>

> [@pettetmw](#):
>
> The problem (I think) is that the `conda update -n mne23 spyder-kernels` command doesn’t seem to have the desired effect

The MNE-Python environment file does not (and cannot) know what version of spyder you have in your `base` environment, so conda will always install the highest version of `spyder-kernels` that is compatible with everything else it is installing at the time. As you’ve already figured out, this means you need to downgrade `spyder-kernels` in your `mne23` environment (or alternatively, you could upgrade the version of spyder in `base`, but that can be trickier).

> [@pettetmw](#):
>
> How do I force `conda update` to downgrade to a specified version, and how do I specify that version?

`conda install spyder-kernels=1.9.4` (use equals sign, not dash)

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [August 6, 2021, 5:01pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/18 "2021-08-06T17:01:58Z")

</div>

The following command:  
`(mne23) mpettet@aloha:~$ conda install spyder-kernels=1.9.4`  
definitely seems to do what we want, but sadly, fails after about 15 minutes, disgorging an epic stream of output detailing all the unresolvable conflicts.

I’ll try Richard’s installer next.

---

<div class="post-metadata">

**Author:** ![pettetmw](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/pettetmw/32/579_2.png) [@pettetmw](https://mne.discourse.group/u/pettetmw)\
**Post date:** [August 6, 2021, 5:11pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/19 "2021-08-06T17:11:16Z")

</div>

Hi @richard, Readme is under construction… I assume I just run the shell script from my home dir? Does it assume anything about existing conda environments? Does it take any arguments, like, e.g., the name of the conda environment being created? FYI, I don’t have an environment called “mne”, so if your script defaults to that name, I guess I can just give it a try? I can wait for instructions to be added to Readme if that’s already in your queue. Thanks, -Mark

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [August 6, 2021, 5:50pm UTC](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274/20 "2021-08-06T17:50:39Z")

</div>

Hello, it’s an interactive installer that will prompt you for a destination 🙂 it will not interfere with existing Python or MNE installs

We’ll publish an updated readme very soon!

[Next page](https://mne.discourse.group/t/problems-running-mne-viz-plot-alignment-from-within-spyder/3274.md?page=2)
