pyinstaller的scipy导入错误

时间:2018-07-10 14:10:35

标签: python scipy pyinstaller

我正在尝试使用pyinstaller和.spec文件为我的项目构建“一个文件”可执行文件。规格文件的内容如下:

# -*- 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__')

尝试运行可执行文件时出现以下错误:

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.

即使我将scipy.special添加到hiddenimports部分,它也无法导入。

我的环境如下:

  • Windows 10
  • python 3.6.6
  • pyinstaller 3.3.1
  • scipy 1.1.0

1 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题,并且在另一个线程(How do you resolve 'hidden imports not found!' warnings in pyinstaller for scipy?)中找到了解决方案

我用完全相同的代码制作了Chris的答案建议的hook-scipy.py文件:

    from PyInstaller.utils.hooks import collect_submodules
    from PyInstaller.utils.hooks import collect_data_files
    hiddenimports = collect_submodules('scipy')

    datas = collect_data_files('scipy')

像魅力一样工作!希望这对您也有帮助。