Explanation: Python's stack-limit is a safety-belt against endless recursion, eating up memory. PyInstaller imports modules recursively. If the structure how modules are imported within your program is awkward, this leads to the nesting being too deep and hitting Python's stack-limit. With the default recursion limit (1000), the recursion error occurs at about 115 nested imported, with limit 2000 at about 240, with limit 5000 at about 660. Build exe failed!为什么失败
时间: 2024-03-07 08:54:25 浏览: 262
该错误的原因是因为程序中有递归嵌套的模块导入,导致递归深度超过Python的堆栈限制。这会导致程序尝试使用过多的内存,最终导致构建可执行文件失败。在构建可执行文件时,PyInstaller会尝试导入程序中使用的所有模块,如果某些模块之间的导入方式不正确,则可能会导致递归深度过大。要解决这个问题,需要优化程序的模块导入结构,以确保递归深度合理,并且不会超过Python的堆栈限制。
相关问题
Explanation: Python's stack-limit is a safety-belt against endless recursion, eating up memory. PyInstaller imports modules recursively. If the structure how modules are imported within your program is awkward, this leads to the nesting being too deep and hitting Python's stack-limit. With the default recursion limit (1000), the recursion error occurs at about 115 nested imported, with limit 2000 at about 240, with limit 5000 at about 660.
这段话主要讲的是Python的堆栈限制问题。Python的堆栈限制是为了防止无限递归而导致内存被耗尽。而PyInstaller会递归地导入模块。如果你的程序中模块的导入结构不太合理,就会导致递归嵌套过深,从而超出Python的堆栈限制。默认的递归限制是1000,大约在115个嵌套导入时就会出现递归错误,限制为2000时约为240个,限制为5000时约为660个。
============================================================= A RecursionError (maximum recursion depth exceeded) occurred. For working around please follow these instructions ============================================================= 1. In your program's .spec file add this line near the top:: import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5) 2. Build your program by running PyInstaller with the .spec file as argument:: pyinstaller myprog.spec 3. If this fails, you most probably hit an endless recursion in PyInstaller. Please try to track this down has far as possible, create a minimal example so we can reproduce and open an issue at https://github.com/pyinstaller/pyinstaller/issues following the instructions in the issue template. Many thanks. Explanation: Python's stack-limit is a safety-belt against endless recursion, eating up memory. PyInstaller imports modules recursively. If the structure how modules are imported within your program is awkward, this leads to the nesting being too deep and hitting Python's stack-limit. With the default recursion limit (1000), the recursion error occurs at about 115 nested imported, with limit 2000 at about 240, with limit 5000 at about 660. 翻译一下
出现了递归错误(超过最大递归深度),需要按照以下步骤进行解决:
1. 在程序的 .spec 文件中,在顶部附近添加以下代码:
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
这将增加Python的递归深度限制,以防止出现此错误。
2. 使用 .spec 文件作为参数运行 PyInstaller 来构建程序:
pyinstaller myprog.spec
3. 如果构建失败,则可能是因为 PyInstaller 中出现了无限递归问题。请尝试跟踪此问题,创建一个简化的示例程序以便我们能够重现,然后在 https://github.com/pyinstaller/pyinstaller/issues 上开启一个问题并按照问题模板中的说明进行操作。
这个错误的原因是因为Python的堆栈限制是为了防止无限递归和内存泄漏。PyInstaller会递归地导入程序中使用的所有模块,如果模块之间的导入结构不合适,则可能会导致递归深度过大,从而触发此错误。默认情况下,Python的递归深度限制是1000,如果超过此限制,则会出现递归错误,而递归深度限制可以通过上述第一步中的代码进行修改。
阅读全文