简体   繁体   English

pyinstaller的scipy导入错误

[英]scipy import error with pyinstaller

I am trying to build a "One File" executable for my project with pyinstaller and a .spec file. 我正在尝试使用pyinstaller和.spec文件为我的项目构建“一个文件”可执行文件。 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. 尝试导入scipy.special时,它失败了,即使我已将它添加到hiddenimports部分中。

My environment is as follows: 我的环境如下:

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

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? ) 我遇到了完全相同的问题,并且在另一个线程中找到了解决方案,( 如何解决pyinstaller中针对“ scipy”的“找不到隐藏的进口!”警告?

I made the hook-scipy.py file that Chris's answer suggested with the exact same code: 我使用完全相同的代码制作了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')

Worked like a charm! 像魅力一样工作! Hope this helps you as well. 希望这对您也有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM