Nuitka是一个Python编译器,它将Python代码编译成C程序,然后链接到libpython库。它不仅能提供相当好的保护,还能带来2-4倍的性能提升。 1. 安装nuitka
pip install nuitka
2. 使用nuitka
python -m nuitka --onefile --follow-imports --output-dir=dist Test2\final.py
-
--follow-imports: 自动包含所有依赖项(非常重要!)。
-
--onefile: 打包成单个 EXE 文件。
-
--windows-disable-console: 如果是 GUI 程序,隐藏黑色命令行窗口。
-
--output-dir=dist: 将打包结果输出到 dist 文件夹,保持根目录整洁。2. 使用nuitka
3. 遇到的问题
Nuitka-Options: Used command line options:
Nuitka-Options: Test2\error_scale.py
Nuitka-Options:WARNING: You did not specify to follow or include anything but main program. Check options and make sure that is intended.
Nuitka: Starting Python compilation with:
Nuitka: Version '2.8.4' on Python 3.10 (flavor 'CPython Official') commercial grade 'not installed'.
Nuitka: Completed Python level compilation and optimization.
Nuitka: Generating source code for C backend compiler.
Nuitka: Running data composer tool for optimal constant value handling.
Nuitka: Running C compilation via Scons.
Nuitka-Scons:WARNING: Windows SDK must be installed in Visual Studio for it to be usable with Nuitka. Use the Visual Studio installer for adding it.
Nuitka will use gcc from MinGW64 of winlibs to compile on Windows.
Is it OK to download and put it in 'C:\Users\SS\AppData\Local\Nuitka\Nuitka\Cache\DOWNLO~1\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2'.
Fully automatic, cached. Proceed and download? [Yes]/No :
-
Nuitka-Scons:WARNING: Windows SDK must be installed in Visual Studio...
-
含义: 这是最核心的信息。Nuitka 首先尝试寻找微软的官方 C++ 编译器 (MSVC),它通常是随 Visual Studio 一起安装的。Nuitka 发现你的系统上可能装了 Visual Studio,但缺少了编译 C++ 程序所必需的 "Windows SDK" 组件。
-
原因: 很多人安装 Visual Studio 时,可能只安装了用于其他语言(如 C#)的组件,而没有勾选 "使用 C++ 的桌面开发" 这个工作负载。
-
-
Nuitka will use gcc from MinGW64 of winlibs to compile on Windows.
-
含义: 因为找不到配置完整的 MSVC 编译器,Nuitka 启动了它的 B 计划。它告诉你:“没关系,既然微软的编译器用不了,我可以帮你下载并使用另一个在 Windows 上同样出色的 C++ 编译器——GCC (来自 MinGW64 项目)。”
-
-
Is it OK to download and put it in '...'? ... Proceed and download? [Yes]/No :
-
含义: 这是 Nuitka 在向你请求权限。它问你:“我可以自动下载 GCC 编译器(大约几百MB),并把它放在 Nuitka 的缓存目录里吗?这个过程是全自动的,并且以后编译都会自动使用它。”
-
为了不破坏VS的当前环境,不影响本机其它开发或编译环境,我选择让Nuitka自动下载 GCC 编译器,这样就可以了,只是这个选择编译较慢。
1535

被折叠的 条评论
为什么被折叠?



