Python打包exe,以及解决闪退2.0

前言

两年前写的一篇 Python打包exe,以及解决闪退 是使用pyinstaller进行打包操作 今天这里介绍使用 Nuitka 进行打包
话不多说直接上教程

环境准备

安装配置MinGW
https://sourceforge.net/projects/mingw-w64/files/
版本不要弄错(最低的是8.1.0版本,32和64位的版本要注意)
这里也提供百度云的
链接:https://pan.baidu.com/s/1FrethECefLoWpwgs6Pxjaw?pwd=thpz
提取码:thpz
在这里插入图片描述

在这里插入图片描述

安装 Nuitka

pip install nuitka

这里使用 PyQt5 的一个例子来演示,Nuitka 打包
在这里插入图片描述
如下是一条完整的命令 编译的py文件为画布.py(注意这是入门命令)

nuitka --mingw64 --standalone --show-progress --show-memory --plugin-enable=qt-plugins  --output-dir=out .\qt5\画布.py

以下是常用命令

--mingw64 #默认为已经安装的vs2017去编译,否则就按指定的比如mingw(官方建议)

--standalone 独立环境,这是必须的(否则拷给别人无法使用)

--windows-disable-console 没有CMD控制窗口

--output-dir=out 生成exe到out文件夹下面去

--show-progress 显示编译的进度,很直观

--show-memory 显示内存的占用

--include-qt-plugins=sensible,styles 打包后PyQt的样式就不会变了
--plugin-enable=qt-plugins 需要加载的PyQt插件

--plugin-enable=tk-inter 打包tkinter模块的刚需

--plugin-enable=numpy 打包numpy,pandas,matplotlib模块的刚需

--plugin-enable=torch 打包pytorch的刚需

--plugin-enable=tensorflow 打包tensorflow的刚需

--windows-icon-from-ico=你的.ico 软件的图标

--windows-company-name=Windows下软件公司信息

--windows-product-name=Windows下软件名称

--windows-file-version=Windows下软件的信息

--windows-product-version=Windows下软件的产品信息

--windows-file-description=Windows下软件的作用描述

--windows-uac-admin=Windows下用户可以使用管理员权限来安装

--linux-onefile-icon=Linux下的图标位置

--onefile 像pyinstaller一样打包成单个exe文件

--include-package=复制比如numpy,PyQt5 这些带文件夹的叫包或者轮子

--include-module=复制比如when.py 这些以.py结尾的叫模块

在这里插入图片描述
运行结束后,项目中会多出一个out文件夹
在这里插入图片描述
其中的画布.dist 里面就有打包好的 .exe 文件
在这里插入图片描述
打包挺简单的快去试试吧

最后附带我的例子的代码
Github https://github.com/KingJin-web/python/tree/master/qt5

Gitee https://gitee.com/KingJin-web/python/tree/master/qt5

  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值