使用 pyinstaller DLL 加载编译的脚本失败

Script made compiled with pyinstaller DLL load fail

我用 pyinstaller 编译了一个脚本,它编译得很好,但是当我 运行 程序时,我在控制台中收到以下错误 window。

ImportError: DLL load failed: The specified module could not be found.

我在尝试导入 Crypto 时遇到此错误。为什么会发生这种情况,我该如何解决?

根据the pyinstaller manual

You can verify that hidden import is the problem by using Python's verbose imports flag. If the import messages say "module not found", but the warnproject.txt file has no "no module named..." message for the same module, then the problem is a hidden import.

Hidden imports are handled by hooking the module (the one doing the hidden imports) at Analysis time. Do this as follows:

  1. Create a file named hook-module.py (where module is the fully-qualified Python name, eg, hook-xml.dom.py) and place it somewhere. Remember the place as your private hooks directory.

  2. In the .spec file, pass your private hooks directory as hookspath argument to Analysis so will be searched. Example:

    a = Analysis(['myscript.py'], hookspath='/my/priv/hooks') In most cases the hook module will have only one line:

    hiddenimports = ['module1', 'module2'] When the Analysis finds this file, it will proceed exactly as though the module explicitly imported module1 and module2.

This question似乎相关,答案可能对您也有用。

最后,this report好像也有类似的问题。用户似乎能够通过更新到 pyinstaller 2.1 来修复它,所以如果你还没有尝试的话,你可能想试一试。