简介:pyinstaller常用于打包python文件,当导入的包过多时常会出现一个递归深度超过限制的错误, 这个可以通过设置最大递归深度来解决。
1.pyinstaller报错信息
=============================================================
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.
2.解决方法
在用cmd命令行敲下如下命令
pyinstaller -F a.py
后会在当前路径下生成一个a.spec文件,用记事本打开,在顶部添加以下内容以增大递归深度。
import sys
sys.setrecursionlimit(sys.getrecursionlimit() * 5)
如
- 再用pyinstaller打包a.py的话就用命令
pyinstaller -F a.spec
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)