Open l55p opened 4 months ago
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 ...
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
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
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
it cut off so heres the full error ModuleNotFoundError: No module named 'scipy._lib.array_api_compat.numpy.fft'