python / 学习 · 2023年12月22日 0

python用nuitka打包程序

pyinstaller 6.0版本后移除加密打包

寻找替代打包,安装nuitka

pip install nuitka

一般命令,–windows-disable-console不带cmd控制台窗口,–standalone 独立环境运行,可移植, –onefile打包为单文件

不清理打包产生的文件

nuitka –standalone –onefile –mingw64 –windows-disable-console xx.py

–enable-plugin=tk-inter ,tkinter打包,–remove-output,打包完清除临时文件

清理打包产生的文件

nuitka --standalone --windows-icon-from-ico=./logo.ico --mingw64 --enable-plugin=tk-inter --windows-disable-console --remove-output xx.py

常用参数

–standalone 独立环境,使结果可移植
–windows-disable-console 去掉CMD控制窗口
–output-dir=out 生成exe到out文件夹下面去
–show-progress 显示编译的进度
–show-memory 显示内存的占用
–enable-plugin=pyside6 打包pyside6模块的需要
–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 打包为单个exe文件
–include-package=复制比如numpy,PyQt5 这些带文件夹的叫包或者轮子
–include-module=复制比如when.py 这些以.py结尾的叫模块
–-include-package-data=包含给定软件包名称中的数据文件,等号后软件包名称。有的时候Nuitka并不能正确分析出一些Python软件包所需要使用的数据文件,在运行程序时提示FileNotFoundError等错误,此时就需要使用该选项。如:–include-package-data=ultralytics
–-include-data-files= 按文件名包含数据文件,等号后的格式为<SRC=DEST>。SRC指的是文件夹的路径,DEST指的是文件夹相对于打包结果的路径,其中DEST只能使用相对路径。如:–include-data-files=/Users/admin/Downloads/yolov5n.pt=./yolov5n.pt
-–include-data-dir= 包含文件夹中的数据文件,等号后的格式为<SRC=DEST>。使用方法与–include-data-files=相同。
–follow-import-to=MODULE/PACKAGE 如果使用该模块,请遵循该模块;如果是一个包,请遵循整个包。可以多次给定。默认为空。