使用pyinstaller打包pyqt5报With the default recursion limit (1000)

2 篇文章 0 订阅
1 篇文章 0 订阅

使用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.

如果出现类似问题说明代码没有问题,只是它默认配置出现的问题

解决办法

当支行过一次pyinstaller后此时运行过的目录下会有一个与要打包的.py文件同名的.spec文件
打开*.spec文件在文件头添加两行代码:

import sys
sys.setrecursionlimit(2000)

当然这个2000是不定的,由自己决定改成多少,哪怕100000都可以

关于运行

在修改*.spec文件前执行的是py文件,当修改过spec文件后为了使原程序知道你有修改过什么东西当然得使用*.spec来运行。

pyinstaller -D *.spec

完成打包后生成两个文件目录build和dist

  • build为临时文件目录完成打包后可以删除。
  • dist中存放打包的结果,可执行文件和其它程序运行的关联文件都在这个目录dist下。
  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
PyInstaller是一个用于打包Python文件的库,可以将Python脚本转换成可执行文件。对于使用PyQt5编写的脚本进行打包,首先需要确保已经安装了PyInstallerPyQt5。然后,可以按照以下步骤进行打包: 1. 打开终端或命令提示符窗口,并切换到包含主函数文件的目录。 2. 运行以下命令:`pyinstaller your_script.py`,其中"your_script.py"是你要打包的脚本的文件名。 3. PyInstaller将开始分析脚本并创建.spec文件,该文件将包含有关打包过程的配置信息。 4. 在.spec文件中,你可以对打包过程进行更多的自定义配置。可以使用文本编辑器打开.spec文件并进行修改。 5. 对于PyQt5脚本,通常需要添加额外的参数来解决特定的问题。例如,如果脚本中使用了Qt的平台插件(例如QtWebEngine),可能需要使用`--add-data`参数来包含这些插件。具体的参数配置可以参考PyInstaller的文档。 6. 修改完.spec文件后,运行以下命令:`pyinstaller your_script.spec`,其中"your_script.spec"是你修改后的.spec文件的文件名。 7. PyInstaller将开始根据.spec文件进行打包。在打包完成后,你将在当前目录中看到一个名为"dist"的文件夹,里面包含了打包后的可执行文件。 需要注意的是,PyInstaller打包过程可能因为项目的复杂性而有所不同。建议在打包前仔细阅读PyInstaller的文档,并根据你的具体需求进行适当的配置和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [pyinstaller打包pyqt5项目总结](https://blog.csdn.net/Sheleon1995/article/details/125041861)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [pyinstaller打包pyqt5程序 全过程 超详细](https://blog.csdn.net/okfu_DL/article/details/84566545)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值