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

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

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

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? :slight_smile:

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:

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

            # 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? :slight_smile:
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 :wink:

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

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:

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 states:

We strongly encourage package developers to provide hooks with their packages. See section Providing PyInstaller Hooks with your Package for how easy this is.

At the moment I cannot unfortunately therefore move forward, Iā€™m stacked :disappointed_relieved:
@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 was adding some code related to pyinstaller, maybe he knows something about that?

thanks in advance

Hello,

I still donā€™t think hiddenimports is what you need, but datas.

Nope, Iā€™m afraid youā€™re on your own, sorry.

1 Like

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

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

1 Like