It looks like

pyinstaller --collect-all mne mwe.py

is all it takes to build the example.

On Monday, February 17, 2025 at 11:44:49 AM UTC+1 Clemens Brunner wrote:

Hello!

I'm trying to package a Python script which imports mne 
<https://mne.tools/stable/index.html>, a package that uses lazy loading 
(via the lazy_loader <https://pypi.org/project/lazy-loader/> package).

To reproduce, create a script called mwe.py with the following content:

import mne
print(mne.sys_info())

Then run pyinstaller mwe.py, and try executing the generated app with 
dist/mwe/mwe. This gives the following error (I tried this on macOS):

Traceback (most recent call last):
  File "mwe.py", line 1, in <module>
    import mne
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in 
_find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "mne/__init__.py", line 30, in <module>
  File "lazy_loader/__init__.py", line 342, in attach_stub
ValueError: Cannot load imports from non-existent stub 
'/Users/clemens/Desktop/test-pyinstaller-pyi/dist/mwe/_internal/mne/__init__.pyi'
[PYI-16568:ERROR] Failed to execute script 'mwe' due to unhandled exception!

Any ideas/suggestions on how to make this work? I saw that skimage had a 
similar problem 
<https://github.com/pyinstaller/pyinstaller-hooks-contrib/pull/565>, but I 
don't know how to make it work for mne. Also, it seems like some packages 
have adopted lazy loading <https://scientific-python.org/specs/spec-0001/>, 
such as numpy and scipy, and it would probably be nice to have a solution 
that works for all of these packages.

Thanks!

Clemens

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/pyinstaller/fec2f87d-1e5b-4e46-bc43-8cd8985e9687n%40googlegroups.com.

Reply via email to