【问题标题】:scipy import error with pyinstallerpyinstaller 的 scipy 导入错误
【发布时间】:2018-12-18 10:20:18
【问题描述】:

我正在尝试使用 pyinstaller 和 .spec 文件为我的项目构建一个“一个文件”可执行文件。 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

【问题讨论】:

    标签: python scipy pyinstaller


    【解决方案1】:

    我遇到了完全相同同样的问题,我在另一个线程中找到了解决方案,(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')
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-15
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多