python打包成exe

2023/04/20 

使用Pyinstaller打包exe总结

案例

Pyinstaller -F -w -i chengzi.ico py_word.py

-F 打包exe

-w 不带控制台的打包

-i img 打包指定exe图标打包

自己使用

指令1:

Pyinstaller -F -w -i Rpa_icon.bmp RPA_GYJ_SCENE_1.py

这个会将用到的包全部打包到一个可执行文件中,文件很大,exe执行效率比较低

指令2:

Pyinstaller RPA_GYJ_SCENE_1.py

会生成:RPA_GYJ_SCENE_1.spec

会报【问题1】的错误,按问题1的解决方案解决就行。

接着运行:Pyinstaller RPA_GYJ_SCENE_1.spec

问题

问题1

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的堆栈限制是防止无休止递归的安全带,吞噬记忆。PyInstaller递归地导入模块。如果结构

在程序中导入模块的方式很尴尬,这会导致嵌套太深并且达到Python的堆栈限制。

对于默认的递归极限(1000),递归错误发生在115嵌套导入,限制2000为约240,限制5000为约660.】

1)在程序的RPA_GYJ_SCENE_1.spec文件中,在顶部附近添加以下行:

import sys

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

2)再执行

pyinstaller RPA_GYJ_SCENE_1.spec

问题2

这部分实际上是警告,可以不用管

实际的问题是,定位字符识别模型和字符集文件问题,不知道为什么没有找到它默认的路径:
C:\Users\Administrator\AppData\Roaming\cnocr

D:\ProgramData\Anaconda3\Lib\site-packages\cnocr\label_cn.txt

解决方案:

在代码里指定model 和 label_cn.txt的路径

然后在程序当前目录下创建对应的文件夹,并将模型拷贝到这个文件夹下:

model\2.2\densenet_lite_136-fc\cnocr-v2.2-densenet_lite_136-fc-epoch=039-complete_match_epoch=0.8597-model.onnx

解决问题心得:可以使用工具,但不要太过依赖工具,要去分析问题的原因。

-------------------------------------------------------------------------------------------------------------------------

使用cx-freeze打包exe总结

参考:python- cx_Freeze安装、打包exe文件_python cx_freeze_kun_dl的博客-CSDN博客

pip install cx-freeze

如果当前环境配置的是Anaconda3 就在截图这个地方执行,这个地方和命令行的对话框是一样的 安装的东西会直接和当前配置的环境关联

安装后Anaconda3的script目录下会有三个文件

然后切换到这个目录下执行:python cxfreeze-postinstall               

打包指令:

cxfreeze D:\Kaggle\company\Release_3\img_stitching

_para_test.py --target-dir D:\Kaggle\company\11

遇到的错误::

cx_freeze importError:numpy.core.umath to import

ImportError: numpy.core.multiarray failed to import

解决方法是更新numpy :pip install -U numpy,然后添加:                 

import numpy.core._methods

import numpy.lib.format

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值