网站维护计划,成都个人学做网站,深圳企业网站建设制作,专业企业展厅设计公司文章目录 写在前面参考准备工作Quick Start参数说明使用打包程序输出目录结构日志2023.09.20 写在前面 
本文的demo示例的代码/数据可从笔者的GitCode获取: HelloWorld 
参考 
Nuitka官网: https://github.com/Nuitka/NuitkaNuitka使用: https://daobook.github.io/nuitka-doc/… 文章目录 写在前面参考准备工作Quick Start参数说明使用打包程序输出目录结构日志2023.09.20   写在前面 
本文的demo示例的代码/数据可从笔者的GitCode获取: HelloWorld 
参考 
Nuitka官网: https://github.com/Nuitka/NuitkaNuitka使用: https://daobook.github.io/nuitka-doc/zh_CN/user-manual.html#use-cases 
准备工作 
工作环境: Windowns10 python版本: Python 3.10.7 安装Nuitka pip install nuitka下载 gcc 下载地址 https://github.com/brechtsanders/winlibs_mingw/releases 如果没有下载或下载的版本不对应的话在打包时会提示相应安装包是否下载, 选择输入Yes”下载即可. 如果自行下载的 gcc 包, 解压后配置用户环境变量, 将解压路径 xxx\bin 添加的用户环境变量中. PS: 笔者执行打包时, 还提示安装ccache, 选择Yes自动下载 使用的下载路径.  
Quick Start 
先构建项目demo脚本, 打印一些信息然后输入文件并读取第一列后再输出. 
测试脚本: 
python hello.py -i test/data.txt -o test/data.pro.txt主脚本测试完成后, 开始打包: 
# 开始打包主脚本 hello.py
python -m nuitka \--output-dir./hellooo \--standalone --show-memory --show-progress \--follow-import-toutils,src \--windows-icon-from-ico./logo.ico \hello.py参数说明 
参数说明–output-dir指定输出的结果路径–standalone打包成独立的文件–show-progress显示打包进度–show-memory显示占用内存–follow-import-to指定打包时同时打包的源码文件夹用,分隔–windows-icon-from-ico指定打包程序exe的图标其他参数–mingw64指定编译器–nofollow-imports不编译代码中所有的import–plugin-enable需要加载的插件–windows-disable-console–recurse-all–recurse-not-to–onefile–remove-output–disable-console 使用打包程序 
打包程序在输出目录 outdir/xxx.dist/xxx.exe 
# 打包程序看help
./hellooo/hello.dist/hello.exe --help# 使用打包后程序
./hellooo/hello.dist/hello.exe -i test/data.txt -o test/data.test_pack.txt输出目录结构 
执行打包程序后输出目录的文件结构如下 
$ tree.com //a //f 
---hello.build
|   |   .sconsign-310.dblite
|   |   link_input.txt
|   |   build_definitions.h
|   |   ccache-24780.txt
|   |   module.src.c
|   |   module.src.const
|   |   module.src.o
|   |   module.src.source1.c
|   |   module.src.source1.const
|   |   module.src.source1.o
|   |   module.utils.c
|   |   module.utils.const
|   |   module.utils.o
|   |   module.utils.source2.c
|   |   module.utils.source2.const
|   |   module.utils.source2.o
|   |   module.__main__.c
|   |   module.__main__.const
|   |   module.__main__.o
|   |   scons-report.txt
|   |   __bytecode.const
|   |   __constants.bin
|   |   __constants.c
|   |   __constants.const
|   |   __constants.h
|   |   __constants.o
|   |   __constants.txt
|   |   __helpers.c
|   |   __helpers.h
|   |   __helpers.o
|   |   __loader.c
|   |   __loader.o
|   |
|   \---static_src
|           CompiledFunctionType.c
|           CompiledFunctionType.o
|           MainProgram.c
|           MainProgram.o
|
\---hello.disthello.exepython310.dllucrtbase.dllunicodedata.pydvcruntime140.dll_bz2.pyd_decimal.pyd_lzma.pyd当前demo示例下删除了这些文件, 只保留了 hellooo/hello.dist/hello.exe主程序文件 (4.27M)。 
日志 
2023.09.20 
初始版本