关于pyinstaller打包exe时报错“A RecursionError (maximum recursion depth exceeded) occurred.”

pyinstaller demo.py打包exe程序时报错


问题描述

pyinstaller demo.py时出现如下问题:

=============================================================
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.

原因分析:

python默认的递归深度是很有限的(默认是1000),因此当递归深度超过999的样子,就会引发这样的一个异常。这个错误是在 pyinstaller在打包的过程中产生的,是我的python程序导入的库带来的问题。这需要修改系统递归层数限制(recursion limit)来解决。.spec文件是在pyinstaller打包过程中分析程序产生的。打包成exe文件可以直接从.spec文件开始。因此在执行pyinstaller过程中修改系统递归层数限制,可以通过修改*.spec文件来实现。


解决方案:

打开demo.spec文件,添加下面两行。第二行代码根据自己报错时的提示填写。

import sys
sys.setrecursionlimit(sys.getrecursionlimit()*5)

然后再打包:执行“pyinstaller demo.spec”


参考资料

1、https://blog.csdn.net/weixin_42691768/article/details/84781789
2、https://blog.csdn.net/cd_yourheart/article/details/114024773

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值