简体   繁体   English

Pyinstaller - “致命错误! 使用 multiprocessing.freeze_support 时无法执行脚本”

[英]Pyinstaller - “Fatal error ! Failed to execute script” when using multiprocessing.freeze_support

I am using pyinstaller(v3.2.1) to build a --onefile windows exe.我正在使用 pyinstaller(v3.2.1) 来构建一个 --onefile windows exe。 I am using multiprocessing within my python (v3.5.3) script.我在我的 python (v3.5.3) 脚本中使用多处理。 I have implemented the below mentioned workaround for windows.我已经为 Windows 实现了下面提到的解决方法。

Recipe Multiprocessing 配方多重处理

Logically, my python script does not span multiple process unless required / conditions are met and is working as expected.从逻辑上讲,除非满足要求/条件并且按预期工作,否则我的 python 脚本不会跨越多个进程。 The issue I have is that, whenever multiple processes are involved, everything seems fine.我的问题是,每当涉及多个进程时,一切似乎都很好。 But in case, if multiprocess is not involed, the below "Fatal: Could not execute the script" dialog box flashes for couple of seconds or more and then disappears still returning the expected results.但是,如果不涉及多进程,下面的“致命:无法执行脚本”对话框会闪烁几秒钟或更长时间,然后消失,但仍返回预期结果。

在此处输入图片说明

Is there anything I am missing that is causing the fatal error dialog to appear and disappear ?我是否遗漏了什么导致致命错误对话框出现和消失? I suspect the multiprocessing.freeze() statement right after if __name__ == __main__ : might be causing the issue when new processes are not created!我怀疑在if __name__ == __main__ :之后的multiprocessing.freeze()语句if __name__ == __main__ :可能会在未创建新进程时导致问题!

I had the same issue and followed Eugene Chabanov's advise of using pyinstaller without any special characters just pyinstaller yourapp.py , when the exe was ready I opened it using the windows CMD and it got stuck in CMD with the error:我遇到了同样的问题,并遵循了 Eugene Chabanov 的建议,即使用 pyinstaller 没有任何特殊字符,只是pyinstaller yourapp.py ,当 exe 准备好时,我使用 Windows CMD 打开它,它卡在 CMD 中并出现错误:

ModuleNotFoundError: No module named 'babel.numbers'

I then ran pyinstaller again this time pyinstaller -F --hidden-import "babel.numbers" test.py and it works beautifully.这次我再次运行 pyinstaller pyinstaller -F --hidden-import "babel.numbers" test.py并且它运行pyinstaller -F --hidden-import "babel.numbers" test.py漂亮。

Try to see what error you get and if it is "ModuleNotFoundError" then just run pyinstaller adding --hidden-import "missing_module_name" .试着看看你得到了什么错误,如果它是“ModuleNotFoundError”,那么只需运行 pyinstaller 添加--hidden-import "missing_module_name"

I hope it helps.我希望它有帮助。

These people deserve the credit for helping me:这些人因帮助我而值得称赞:

--hidden-import "missing_module_name" - MR --hidden-import "missing_module_name" - 先生

run without windowed - Eugene Chabanov无窗口运行 - Eugene Chabanov

I've had similar issue and solved it by running compile command without -windowed prefix and then launching exe file using command line.我遇到了类似的问题,并通过运行没有-windowed前缀的编译命令然后使用命令行启动 exe 文件来解决它。 It allowed to see where the error was.它允许查看错误在哪里。 Script was referring to a file that wasn't there.脚本指的是一个不存在的文件。 Error popped out on another computer, while everything was ok on mine.错误在另一台计算机上弹出,而我的一切正常。 (because of hardcoded file in place) (因为硬编码文件就位)

This error is often associated with a script that request some data from a directory and the directory isn't built into the exe.此错误通常与从目录请求一些数据的脚本相关联,并且该目录未内置到 exe 中。

If your script has some sort of data from somewhere, be sure that the data files that are in your source folder are also in the frozen app.如果您的脚本有来自某处的某种数据,请确保源文件夹中的数据文件也在冻结的应用程序中。

To add data files to the frozen app, see http://pyinstaller.readthedocs.io/en/latest/spec-files.html#adding-files-to-the-bundle要将数据文件添加到冻结的应用程序,请参阅http://pyinstaller.readthedocs.io/en/latest/spec-files.html#adding-files-to-the-bundle

After a glorious fight with this issue, I found that my modules were installed in my IDE rather than my actual python run environment.在与这个问题进行了一场光荣的斗争后,我发现我的模块安装在我的 IDE 中,而不是我实际的 python 运行环境中。 This resulted in everything working perfectly when I ran in the IDE but it failed to reference the modules when I ran the .exe.这导致我在 IDE 中运行时一切正常,但是当我运行 .exe 时它无法引用模块。 To solve this I opened the directory where my .py file was located in my cmd line and simply re-installed my dependencies there and everything worked.为了解决这个问题,我打开了 .py 文件在我的 cmd 行中所在的目录,然后简单地在那里重新安装了我的依赖项,一切正常。 I hope this works for you because I was beating my head against the wall for days without finding any solutions online.我希望这对你有用,因为我几天来一直在用头撞墙而没有在网上找到任何解决方案。

Try running as Admin.尝试以管理员身份运行。 I had the same problem because I wanted to create some files at "Program Files".我遇到了同样的问题,因为我想在“程序文件”中创建一些文件。

After a long time researching I found two issues with my code:经过长时间的研究,我发现我的代码有两个问题:

  1. pynput only works with 1.6.8 (pip install pynput==1.6.8) See answer from Sandeep pynput 仅适用于 1.6.8 (pip install pynput==1.6.8) 请参阅 Sandeep 的回答
  2. I had an icon iconbitmap(r'icon.ico') in my file.我的文件中有一个图标 iconbitmap(r'icon.ico')。 This icon file was not found when processing.处理时未找到此图标文件。 I replaced it with the full path starting 'C:....' and it worked.我用以“C:....”开头的完整路径替换了它,并且它起作用了。

I was able to troubleshoot (sometimes it showed errors sometimes not) by typing YourProgramName.exe in terminal (make sure your in the right directory).通过在终端中键入 YourProgramName.exe(确保您在正确的目录中),我能够进行故障排除(有时显示错误有时不显示)。 Then it shows what doesn't work out.然后它显示什么不起作用。

I faced the same error while trying to convert a .py file to a .exe.我在尝试将 .py 文件转换为 .exe 时遇到了同样的错误。

The problem in my case was that I imported a library in my script that wasn't used by the rest of the code.就我而言,问题是我在脚本中导入了一个未被其余代码使用的库。 The weird thing is, that VS wasn't complaining about the fact that this library was totally useless.奇怪的是,VS 并没有抱怨这个库完全没用的事实。

So as a simple first step I would recommend: Go through your script and remove any redundancies.因此,作为一个简单的第一步,我建议:检查您的脚本并删除任何冗余。

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

相关问题 multiprocessing.freeze_support() - multiprocessing.freeze_support() Pyinstaller - “致命错误! 将脚本转换为 exe 时无法执行脚本” - Pyinstaller - “Fatal error ! Failed to execute script” when converting script to exe PyInstaller 致命错误:无法执行脚本 - PyInstaller fatal error: Failed to execute script Pyinstaller执行脚本失败 - Pyinstaller Failed execute script Error PyInstaller“无法执行脚本”错误 - PyInstaller “failed to execute script” Error Pyinstaller [3060] 无法执行脚本 pyi_rth_multiprocessing - Pyinstaller [3060] Failed to execute script pyi_rth_multiprocessing PyInstaller 冻结的 PyQt4 脚本给出了致命错误:“无法执行脚本 xyz” - PyQt4 script frozen by PyInstaller gives Fatal Error:"Failed to execute script xyz" Windows-Pyinstaller 错误“无法执行脚本”当应用程序点击 - Windows- Pyinstaller Error “failed to execute script ” When App Clicked Windows-Pyinstaller 错误“无法执行脚本”当应用程序点击 - Windows- Pyinstaller Error "failed to execute script " When App Clicked 检测到致命错误“无法执行脚本主程序”。与 pyinstaller 一起使用,与 HM NSIS 一起崩溃 - Fatal error detected “Failed to execute script main”.Works with pyinstaller, crash with HM NSIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM