pyinstaller打包程序所遇问题记录

news/2024/5/19 21:30:16 标签: pyinstaller, RecursionError

pyinstaller_0">pyinstaller支持的参数功能

在这里插入图片描述
命令样式:
pyinstaller -w -i “d:\my.ico” -F mypy.py

pyinstaller_RecursionError_maximum_recursion_depth_exceeded_5">python pyinstaller RecursionError: maximum recursion depth exceeded

在调用pyinstaller -F my.py 时报错如下:

递归超过了python的栈高度限制

  File "F:\Program_File\anaconda3\lib\ast.py", line 263, in generic_visit
    self.visit(value)
  File "F:\Program_File\anaconda3\lib\ast.py", line 253, in visit
    return visitor(node)
RecursionError: maximum recursion depth exceeded

解决方案

stackoverflow网友解决方案

Mustafa did guide me to the right direction, you have to increase the recursion limit. But the code has to be put to the beginning of the spec file and not in your python code:

import sys
sys.setrecursionlimit(5000)

Create the spec file with pyi-makespec first, edit it and then build by passing the spec file to the pyinstaller command. See the pyinstaller manual for more information about using spec files.

Please make sure to use pyinstaller 3.2.0, with 3.2.1 you will get ImportError: cannot import name ‘is_module_satisfies’ (see the issue on GitHub)

在此总结下解决步骤:
1)pyinstaller -F xxx.py
这一步肯定会报上述错误导致失败,但是会产生一个xxx.spec文件
2)在xxx.spec文件中增加两行(添加在原文件第二行):

import sys
sys.setrecursionlimit(5000)

再执行 pyinstaller xxx.spec 打包成功。

pyinstaller_Cannot_find_existing_PyQt5_plugin_directories_37">python pyinstaller Cannot find existing PyQt5 plugin directories

问题现象

Exception:
            Cannot find existing PyQt5 plugin directories
            Paths checked: C:/qt64/qt_1544645195969/_h_env/Library/plugins

解决方案

网友方案
I solved it by copying the pyqt5qmlplugin.dll to the path mentioned above C:/qt64/qt_1544645195969/_h_env/Library/plugins. Finally I got the .exe
意思就是:

  1. 手动创建C:/qt64/qt_1544645195969/_h_env/Library/plugins这个目录,
  2. 然后从anaconda下找到pyqt5qmlplugin.dll 这个库拷贝进去

在这里插入图片描述

pyinstaller_utf8_codec_cant_decode_byte_0xce_in_position_123_invalid_continuation_byte_52">python pyinstaller ‘utf-8’ codec can’t decode byte 0xce in position 123: invalid continuation byte

问题现象

----------------------------------------
'utf-8' codec can't decode byte 0xce in position 123: invalid continuation byte
These are the bytes around the offending byte:

解决方案

思路:编码格式问题(可直接解决问题)

  1. 改变控制台的编码格式为utf-8 解决方法,先在控制台中输入 chcp 65001切换控制台编码格式,再执行打包命令

如果还不行:
尝试将中文解释都去掉

pyinstaller_67">python pyinstaller打包程序启动失败

现象

This application failed to start because it could not find or load the Qt platform plugin “windows”.

解决方案

吧这个文件夹,拷贝到执行程序同目录即可:
如果是anaconda环境,
c:\Program_File\anaconda3\Library\plugins\platforms

如果是python 环境:
C:\Python33\Lib\site-packages\PyQt5\plugins\platforms

pyinstallerexeexe_300M_78">pyinstaller打包程序exe过大(exe 300多M)

这个问题纠结了我两天,最终解决了

问题根源

  • 大部分是因为我们使用anaconda,然后包了一些库,例如 xlwings,openxl等包完,不用说直接上300M以上
  • 原因是anaconda库的关联关系太复杂,打包程序pyinstaller默认把相关的全部打包进去了
  • anaconda环境下大包的程序exe

解决方法

  • 最好用的办法就是新建python venv,在新的环境下去打包
  • 新建方法参考我另一篇博文: 如何新建python venv
  • 新建后,调用pyinstaller 打包,所调用的库、包都是新建的venv中的,和anaconda无关了
(venv) D:\pyvenv_a\venv>pyinstaller -F pyexcel\RWExcel.py pyexcel\operfile.py
......
1135 INFO: Bootloader d:\pyvenv_a\venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
21135 INFO: checking EXE
21139 INFO: Building because toc changed
21140 INFO: Building EXE from EXE-00.toc
21141 INFO: Appending archive to EXE D:\pyvenv_a\venv\dist\RWExcel.exe
21169 INFO: Building EXE from EXE-00.toc completed successfully.

新建venv打包结果:

已经很小了,40M左右,(本身里边包含python解析器信息,基本都会大于10M)
更改环境后打包

顺带解决上述三问题

  1. 上述描述的三个问题,也随之不见了,意外中都被解决了

结论

  1. 解决以上所有问题,最好的版本就是新建python venv,基本能隔离很多问题
  2. 我们同时也可以推断出来,编码错误、堆栈到达上线等问题都是anaconda依赖库导致的间接问题,anaconda在给我们带来方便的同时,也挖了不少坑

http://www.niftyadmin.cn/n/1261080.html

相关文章

python实现凯撒密码小组分工_python版实现凯撒密码

import os#-*-coding:utf-8-*-### 凯撒密码(caesar)是最早的代换密码,对称密码的一种 ## 算法:将每个字母用字母表中它之后的第k个字母(称作位移值)替代 ###def encryption():str_raw input("请输入明文:")k int(input("请输入位移值&a…

读懂 互联网巨头 【中台之战】 以及 中台 发展思维

与战略重组几乎同步,阿里、腾讯、百度、京东、美团等一众互联网巨头正纷纷加入“中台战事”。“中台”热度陡增的背后,是管理团队对企业未来深层次的忧虑。中台是应对大公司病的一剂良药吗? 2018年年底到2019年年初,一场组织变革的…

一行多个div_如何用一行 CSS 实现 10 种现代布局?

Mom, I Cant Learn Anymore(《妈妈,我学不动了!》) 是一系列关于计算机领域程序最新时事的文章(偏向于前端领域),在该系列会从不同的角度讨论领域内的实践和进展。前言 周日在家看 web.dev 的 2020 三天 live,发现不少有意思的东西…

python利用xlwings库 处理excel 效率 及其他总结-持续更新

xlwings 入门及使用方式指导 我对比了openxl 和 xlwings的官方文档,发现xlwings的官网API说明很清楚简洁,如果你刚入门,不要去百度按照功能搜索一句句的去拼接代码,直接花一个小时看下API接口说明,基本你就会用了同时…

多路径配置udev_学习笔记:Linux多路径配置 multipath实现设备用户组绑定详细设置...

天萃荷净Linux多路径软件配置,通过multipath实现设备用户组绑定详细设置现在的Linux系统中,很多都会使用系统自带的multipath多路径软件,在以前的版本中,我们一般通过multipathudev或者multipathrc.local来实现多路径和权限设置,而在redhat 5.3-5.11的版本中multipa…

机器学习原来这么有趣!第一章:全世界最简单的机器学习入门指南

第一章:全世界最简单的机器学习入门指南 https://blog.csdn.net/wskzgz/article/details/89917343 第二章:用机器学习制作超级马里奥的关卡 https://blog.csdn.net/wskzgz/article/details/89945137 第三章:图像识别-深度学习与卷积神经网络 https://blo…

笔记本玩rust卡顿_《腐蚀RUST》steam销量第一,延迟高用斧牛加速器!

本周Steam如期公布了上周(1月4日至1月10日)的游戏销量排行榜。本期排行榜中老游戏《腐蚀》凭借打折冲到榜首,七连冠的《赛博朋克2077》跌至第三名。凭借着促销的热度,《腐蚀(RUST)》这款老游戏一口气冲到了排行榜第一名的位置。由于Twitch主播的推广&…

全排列--小结

从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当mn时所有的排列情况叫全排列。 如1,2,3三个元素的全排列为:1,2,31,3,22,1,32,3,13,1,23,2,1共3*2*16种 3&…