============================================================= 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. 翻译一下
时间: 2023-08-09 16:08:17 浏览: 119
出现了递归错误(超过最大递归深度),需要按照以下步骤进行解决:
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,如果超过此限制,则会出现递归错误,而递归深度限制可以通过上述第一步中的代码进行修改。
阅读全文