问题
I am trying to build a "One File" executable for my project with pyinstaller and a .spec file. The content of the spec file is as follows:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['__main__.py'],
pathex=['D:\\opt_frame'],
binaries=[],
datas=[],
hiddenimports=['scipy.special', 'scipy.special.comb'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='__main__',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='__main__')
I am getting the following error when I am trying to run the executable:
File "site-packages\scipy\special\__init__.py", line 640, in <module>
File "d:\opt_frame\.venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
ImportError: DLL load failed: The specified module could not be found.
It fails when trying to import scipy.special even though I have added it to hiddenimports section.
My environment is as follows:
- Windows 10
- python 3.6.6
- pyinstaller 3.3.1
- scipy 1.1.0
回答1:
I had the exact same problem and I found a solution in another thread, (How do you resolve 'hidden imports not found!' warnings in pyinstaller for scipy?)
I made the hook-scipy.py file that Chris's answer suggested with the exact same code:
from PyInstaller.utils.hooks import collect_submodules
from PyInstaller.utils.hooks import collect_data_files
hiddenimports = collect_submodules('scipy')
datas = collect_data_files('scipy')
Worked like a charm! Hope this helps you as well.
来源:https://stackoverflow.com/questions/51267453/scipy-import-error-with-pyinstaller