python 使用 pyinstaller,nuitka 打包 exe

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 一、pyinstaller
    • 1.安装
    • 2.使用
  • 二、nuitka
    • 1.安装
    • 2.使用
  • 总结


# 前言

提示:python打包成exe。


开发出来的工具 需要打包成单独文件 让其他人运行 pyinstaller 执行速度有点慢 ,代码没有加密、nuitka 执行速度很快,代码有加密

python版本:3.7.10

pyinstaller 官方文档https://pyinstaller.readthedocs.io/en/stable/usage.html

nuitka 官方文档https://www.nuitka.net/doc/user-manual.html#use-case-1-program-compilation-with-all-modules-embedded

一、pyinstaller

#常用选项
-D, --onedir
创建一个包含可执行文件的单文件夹捆绑包(默认)

-F, --onefile
创建一个文件捆绑可执行文件。

--specpath DIR
用于存储生成的规范文件的文件夹(默认:当前目录)

-n NAME, --name NAME
分配给捆绑的应用程序和规范文件的名称(默认值:第一个脚本的基本名称)

1.安装

建议在conda里打包,pyinstaller会把环境里安装的包都打包 ,所以单独建一个打包环境会缩小体积

pip install pyinstaller

2.使用

#使用以下命令会生成一个spec文件
pyinstaller -F test.py

image-20210427115204256

如果有静态资源需要编辑spec文件

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2rD6SGrZ-1619508483556)(https://i.loli.net/2021/04/27/jiqw3o6VhnkAguN.png)]

标注静态资源文件夹

pyinstaller test.spec
#打包完成后在当前目录下dist 执行 test.exe

二、nuitka

#常用选项
--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文件(2021年我会再出教程来解释)

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

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

1.安装

python -m pip install nuitka

使用命令验证 python -m nuitka --version
#下载mingw64 安装配置环境变量
https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download

2.使用

#我用到的命令
nuitka --mingw64 --standalone --show-progress --show-memory --plugin-enable=qt-plugins --include-qt-plugins=sensible,styles --output-dir=out  qt_app.py
nuitka --standalone --windows-disable-console  --mingw64 --nofollow-imports --show-memory --show-progress --plugin-enable=qt-plugins --include-qt-plugins=sensible,styles --follow-import-to=util,statics,frame,config --output-dir=o main.py

总结

e-qt-plugins=sensible,styles --output-dir=out qt_app.py



# 总结

你可能感兴趣的:(乱七八糟,pyinstaller,python)