# Pyinstaller issue while building the .exe of a script using MNE

**URL:** <https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480>\
**Category:** Support & Discussions\
**Tags:** installer\
**Created:** [August 2, 2021, 6:58pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480 "2021-08-02T18:58:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [August 2, 2021, 6:58pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/1 "2021-08-02T18:58:06Z")

</div>

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

- MNE-Python version: 0.22.0
- operating system: Windows

Hi @larsoner and @richard ,  
I tried to generated with pyinstaller a .exe of a script containing MNE , and it get built fine, but once I run MNE it from the .exe I receive the error: “montage\standard\_1085.elc not exist”.

Are some of you familiar with this issue? I believe that a solution of this issue could be extremely useful to MNE users.

I’ve seen that another user had the same problem but he could not find a solution, please see: [PyInstaller - Runtime error with mne libraries](http://pyinstaller.47505.x6.nabble.com/Runtime-error-with-mne-libraries-td2433.html)

In particular would be really useful to know how to customize the .spec file in order to fix the issue, for example specifying in the “hidden import” field this missing file, but it is just an rough idea.

With your help I’m sure we could find a solution, and I will be so thankful and glad to help to generate a quick guide to solve this issue and get the .exe fully working.

Would you like to help? Thanks in advance!

Marco

---

<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 2, 2021, 7:04pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/2 "2021-08-02T19:04:25Z")

</div>

Hello @BaggioMarco,

unfortunately I won’t have much time to look into details, but I’m quite certain you’ll have to to supply the `datas` parameter to `Analysis` in order to include those non-Python files in the installer bundle.

May I ask what use case you’re trying to address? 🙂

---

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [August 2, 2021, 7:28pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/3 "2021-08-02T19:28:35Z")

</div>

thanks @richard …sorry I referred to “standard\_1005.elc”.  
I will try to add it in someway through the “data” to be added in the .spec and I’ll let you know how it works.  
I will try to use this file:

> <https://github.com/mne-tools/mne-python/blob/main/mne/channels/data/montages/standard_1005.elc>

This is the block in my script that is related to the issue

```python
            # If EEG channels use the standard naming strategy, By supplying the 'montage' parameter, approximate locations will be added for them
            montage = 'standard_1005' # importante se voglio plottare la location dei canali
            info.set_montage(montage) # Initialize required fields
            info['description'] = 'EEG analysis' # Optional, general description of the project

```

> May I ask what use case you’re trying to address? 🙂  
> Sure!!! I love to make standalone that can run on my laptops where python is not installed.  
> In this case it would allow me to run the EEG analysis without an IDE and python. Alternatively I should keep all my laptops updated in term of python packages version but it is too time consuming, most of the times packages are outdated or too updated and generate errors…I don’t want to deal with it anymore, I find this solution with pyinstaller that it is much more convenient to use once you reach the end with your script.

I will make some trial in the next days! I’ll keep this thread updated, if you or @larsoner could share some more ideas I will try to follow them, thank you 😉

---

<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 3, 2021, 4:28pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/4 "2021-08-03T16:28:12Z")

</div>

> [@BaggioMarco](#):
>
> I love to make standalone that can run on my laptops where python is not installed.  
> In this case it would allow me to run the EEG analysis without an IDE and python. Alternatively I should keep all my laptops updated in term of python packages version but it is too time consuming

I’ve been working a bit on stand-alone MNE-Python installers that should make it very simple to install and update MNE. Do you think this could help you?

[https://github.com/hoechenberger/mne-installers/releases/tag/v2021.1-pre.3](https://github.com/hoechenberger/mne-installers/releases/tag/v2021.1-pre.3)

---

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [August 5, 2021, 6:16pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/5 "2021-08-05T18:16:17Z")

</div>

thanks @richard I really appreciated but I’m aiming to generate the standalone using pyinstaller.  
I have some more updates. First of all, looking at the program files of the standalone I noted that:  
Not only "mne/channels/data/montages/standard\_1005.elc " file is not present, but the entire mne folder is not present, that’s why I did some more tests with pyinstaller, specifying in the ‘hidden import’ field of the .spec file that mne have to be imported. An example below, of how I added it in the .spec file:

```python
a = Analysis(   
    hiddenimports=["mne"],
    .....

```

However it doesn’t work… mne is not imported. Reading a bit the pyinstaller site, it looks like that the main issue is that mne, unlike other packages/modules, doesn’t have a pyinstaller hook. Pyinstaller [website](https://pyinstaller.readthedocs.io/en/stable/hooks.html) states:

> We strongly encourage package developers to provide hooks with their packages. See section [Providing PyInstaller Hooks with your Package](https://pyinstaller.readthedocs.io/en/stable/hooks.html#provide-hooks-with-package) for how easy this is.

At the moment I cannot unfortunately therefore move forward, I’m stacked 😥  
@richard do you know someone in this great MNE community that ever tried to use pyinstaller with MNE and that could share some ideas about this issue? I’ve seen that @larsoner in this [file](https://github.com/mne-tools/mne-realtime/blob/main/.gitignore) was adding some code related to pyinstaller, maybe he knows something about that?

thanks in advance

---

<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 5, 2021, 6:34pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/6 "2021-08-05T18:34:31Z")

</div>

Hello,

I still don’t think `hiddenimports` is what you need, but `datas`.

> [@BaggioMarco](#):
>
> do you know someone in this great MNE community that ever tried to use pyinstaller with MNE and that could share some ideas about this issue

Nope, I’m afraid you’re on your own, sorry.

---

<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:** [August 5, 2021, 7:55pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/7 "2021-08-05T19:55:54Z")

</div>

FYI, the lines related to PyInstaller in the .gitignore file you mentioned are part of the GitHub-provided default gitignore file Python-based projects, see here: [gitignore/Python.gitignore at 991e760c1c6d50fdda246e0178b9c58b06770b90 · github/gitignore · GitHub](https://github.com/github/gitignore/blob/991e760c1c6d50fdda246e0178b9c58b06770b90/Python.gitignore#L29-L33)

In other words, they don’t indicate that anyone on our team has ever used PyInstaller with MNE-Python.

---

<div class="post-metadata">

**Author:** ![timonmerk](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/timonmerk/32/276_2.png) [@timonmerk](https://mne.discourse.group/u/timonmerk)\
**Post date:** [March 5, 2025, 11:27am UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/8 "2025-03-05T11:27:38Z")

</div>

Some years later, I am facing the exact same issue as @BaggioMarco.

> ValueError: Cannot load imports from non-existent stub ‘/var/folders/k2/g3zyypzx0nq2\_w67q\_1j4kbc0000gn/T/\_MEI6jqUIz/mne/ **init**.pyi’

I am therefore also not sure how I can use pyinstaller 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:** [March 25, 2025, 6:59pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/9 "2025-03-25T18:59:16Z")

</div>

> [@timonmerk](#):
>
> I am therefore also not sure how I can use pyinstaller with mne.

I think @cbrnr hit (and fixed) a similar error recently; see [this comment](https://github.com/mne-tools/mne-python/issues/12388#issuecomment-2667954920)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 1, 2025, 6:59pm UTC](https://mne.discourse.group/t/pyinstaller-issue-while-building-the-exe-of-a-script-using-mne/3480/10 "2025-04-01T18:59:53Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
