Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not running #438

Open
l55p opened this issue Jun 25, 2024 · 4 comments
Open

File not running #438

l55p opened this issue Jun 25, 2024 · 4 comments

Comments

@l55p
Copy link

l55p commented Jun 25, 2024

image

it cut off so heres the full error ModuleNotFoundError: No module named 'scipy._lib.array_api_compat.numpy.fft'

@alexandersb98
Copy link

I ran into a similar problem when I created an executable from my Python project.
TL;DR: Add scipy._lib.array_api_compat.numpy.fft and scipy.special._special_ufuncs to your "hidden imports" in your .spec file.

I will try to give some details:
It seems my error message was due to the imports below:

from statsmodels.tsa.holtwinters import ExponentialSmoothing
from statsmodels.tsa.exponential_smoothing.ets import ETSModel

I could run my main.py script without trouble inside VS Code (using Python 3.12.3), but not as an executable.
When I ran the executable I got an error like yours that complained 'scipy._lib.array_api_compat.numpy.fft' could not be found.

I created the executable by first installing "Pyinstaller" (with pip install pyinstaller) and then I ran the command below (in Powershell on Windows 11):
python -m PyInstaller --onedir main.py
Change "main.py" to whatever is the entry point in your project.
From this command I got the executable that didn't work.

Then I googled and found this stackoverflow thread: https://stackoverflow.com/questions/78234168/modulenotfounderror-no-module-named-scipy-linalg-basic
So I tried to add --hidden-import to the pyinstaller command, followed by the name of the module that could not be found, like this:
python -m PyInstaller --onedir --hidden-import scipy._lib.array_api_compat.numpy.fft main.py

Then I got a new error, still a ModuleNotFoundError but this time for the module "scipy.special._special_ufuncs". I added this module name to the hidden imports too, and then the resulting executable could run without problem.

In the end I switched to running the command pyinstaller your_spec_file.spec in order to build the .exe, and before running the command I also specified the hidden imports in my main.spec file (which was generated from running either of the pyinstaller commands above). They can be specified as follows:

# beginning of main.spec
# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=['scipy._lib.array_api_compat.numpy.fft','scipy.special._special_ufuncs'],
    hookspath=[],
    hooksconfig={},
# remainder of main.spec ...

@kp4ws
Copy link

kp4ws commented Jun 27, 2024

I'm running into the same issue. It only occurs when I try to import circle_fit library, otherwise this error doesn't occur for me. I can run my python scripts fine, but I get this error when trying to build an executable via pyinstaller

@l55p
Copy link
Author

l55p commented Jun 28, 2024

I'm running into the same issue. It only occurs when I try to import circle_fit library, otherwise this error doesn't occur for me. I can run my python scripts fine, but I get this error when trying to build an executable via pyinstaller

you can try using the hidden imports like python -m PyInstaller --onedir --hidden-import scipy._lib.array_api_compat.numpy.fft main.py but replace main.py and scipy._lib.array_api_compat.numpy.fft with yout own imports

@kp4ws
Copy link

kp4ws commented Jul 2, 2024

I'm running into the same issue. It only occurs when I try to import circle_fit library, otherwise this error doesn't occur for me. I can run my python scripts fine, but I get this error when trying to build an executable via pyinstaller

you can try using the hidden imports like python -m PyInstaller --onedir --hidden-import scipy._lib.array_api_compat.numpy.fft main.py but replace main.py and scipy._lib.array_api_compat.numpy.fft with yout own imports

A mix of hidden imports and submodules seemed to work for me. Thanks for the advice!
My executable works now when I build it with this command:
pyinstaller .\app.py --collect-submodules=numpy.f2py --hiddenimport=scipy._lib.array_api_compat.numpy.fft --hiddenimport=scipy.special._special_ufuncs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants