Windows 系统pyinstaller打包成python exe程序

工作中需要把python程序打包成exe过程中,配置pyinstaller,遇到的问题及解决办法,防止以后忘记。
1、配置pyinstaller 环境
首先安装pywin32: pip install pywin32
安装pyinstaller :pip install pyinstaller
注意:如果不先安装pywin32的话会出现很多模块找不到的问题,找了好久再发现是这个问题的,所以最好在安装pyinstalller之前安装pywin32
2、介绍下pyinstaller使用命令:
在这里插入图片描述
假如不要控制台只要界面的话
pyinstaller -F -w python脚本文件
要添加图标的话:pyinstaller -F -i ico图片 python脚本文件

main.py内容如下:
def add(x,y):
return (x+y)
把该脚本打包成有控制台的exe则运行下面的命令:
pyinstaller -F main.py
运行之后则在脚本所在的目录下生成dist 和build文件夹
dist:文件夹下面生成的main.exe就是我们想要的exe程序,点击exe程序运行即可
3、执行打包命令遇到的问题及解决方案:
1)、问题:RecursionError: maximum recursion depth exceeded:该问题是打包的程序深度超出了系统默认的深度
解决方案:

  1. 执行 pyinstaller,会生成 main.spec文件:
  2. 在main.spec文件头加上下面代码
    import sys
    sys.setrecursionlimit(5000)
  3. 再次执行 pyinstaller 和 .spec文件: pyinstaller main.spec即可
    2)、问题:
    File “D:\Python34\lib\site-packages\PyInstaller\hooks\hook-zmq.py”, line 18, in
    hiddenimports.extend(collect_submodules(‘zmq.backend’))
    File “D:\Python34\lib\site-packages\PyInstaller\utils\hooks_init_.py”, line 619, in collect_submodules
    repr(pkg_dir), package))
    File “D:\Python34\lib\site-packages\PyInstaller\utils\hooks_init_.py”, line 90, in exec_statement
    return _exec_python_cmd(cmd)
    File "D:\Python34\lib\site-packages\PyInstaller\utils\hooks_init
    .py", line 77, in __exec_python_cmd
    txt = exec_python(*cmd, env=pp_env)
    File “D:\Python34\lib\site-packages\PyInstaller\compat.py”, line 549, in exec_python
    return exec_command(*cmdargs, **kwargs)
    File “D:\Python34\lib\site-packages\PyInstaller\compat.py”, line 356, in exec_command
    out = out.decode(encoding)
    解决方案:
    找到D:\Python34\lib\site-packages\PyInstaller\compat.py", line 356,
    out = out.decode(encoding)
    修改为:
    out = out.decode(encoding, errors=‘ignore’)
    3)、问题:AttributeError: module ‘enum’ has no attribute ‘IntFlag’
    解决方案:原因:Windows解决多版本python执行pip3时出错AttributeError: module ‘enum’ has no attribute ‘IntFlag’?
    这可能是由enum34包引起的。因为python 3.4中有一个标准库枚举模块,所以您应该卸载enum34,它不再与标准库中的枚举兼容,因为枚举。IntFlag是在python 3.6中添加的
    办法:卸载enum34: pip uninstall enum34
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值