承接前面的文章
https://www.cnblogs.com/passedbylove/p/16759512.html
https://www.cnblogs.com/passedbylove/p/16756063.html
自定义Python插件的setup.py
from distutils.core import setup, Extension def main(): setup(name="fputs", version="1.0.0", include_dirs="/usr/local/include/python3.9", description="Python interface for the fputs C library function", author="passedbylove", author_email="passedbylove@gmail.com", ext_modules=[Extension("fputs", ["fputsmodule.c"])]) if __name__ == "__main__": main()
安装依赖
sudo pkg install python39 py39-pip nuitka-py39 upx pip install nuitka orderedset zstandard -i https://pypi.tuna.tsinghua.edu.cn/simple
由于 Freebsd下,upx不支持i386/i586之外的upx压缩,所以,如果想压缩文件,必须安装x86/32位的Freebsd
编译(32位)-没测试
nuitka3 --plugin-enable=upx --onefile --output-dir=dist test1.py --upx-binary=/usr/local/bin/upx
编译64位
nuitka3 --onefile --output-dir=dist test1.py
64位使用upx报错如下
nuitka3 --plugin-enable=upx --onefile --output-dir=dist test1.py --upx-binary=/usr/local/bin/upx Nuitka-Options:INFO: Used command line options: --plugin-enable=upx --onefile --output-dir=dist test1.py --upx-binary=/usr/local/bin/upx Nuitka:INFO: Starting Python compilation with Nuitka '1.1.5' on Python '3.9' commercial grade 'not installed'. Nuitka:INFO: Completed Python level compilation and optimization. Nuitka:INFO: Generating source code for C backend compiler. Nuitka:INFO: Running data composer tool for optimal constant value handling. Nuitka:INFO: Running C compilation via Scons. Nuitka-Scons:INFO: Backend C compiler: clang (clang). Nuitka-Scons:INFO: Backend linking program with 10 files (no progress information available). Nuitka-Scons:WARNING: You are not using ccache. Nuitka-Postprocessing:INFO: Creating single file from dist folder, this may take a while. Nuitka-Onefile:INFO: Running bootstrap binary compilation via Scons. Nuitka-Scons:INFO: Onefile C compiler: clang (clang). Nuitka-Scons:INFO: Onefile linking program with 1 files (no progress information available). Nuitka-Scons:WARNING: You are not using ccache. Nuitka-Onefile:INFO: Keeping onefile build directory 'dist/test1.onefile-build'. Nuitka-Onefile:INFO: Using compression for onefile payload. Nuitka-Onefile:INFO: Onefile payload compression ratio (31.25%) size 17042132 to 5324924. Nuitka:INFO: Keeping dist folder 'dist/test1.dist' for inspection, no need to use it. Nuitka:INFO: Keeping build directory 'dist/test1.build'. Nuitka-Plugins:INFO: upx: Compressing 'dist/test1.bin'. FATAL: upx: Error, call to '/usr/local/bin/upx' failed: ['/usr/local/bin/upx', '-q', '--no-progress', 'dist/test1.bin'] -> b'upx: dist/test1.bin: UnknownExecutableFormatException\n'.
64位编译成功如下
nuitka3 --onefile --output-dir=dist test1.py Nuitka-Options:INFO: Used command line options: --onefile --output-dir=dist test1.py Nuitka:INFO: Starting Python compilation with Nuitka '1.1.5' on Python '3.9' commercial grade 'not installed'. Nuitka:INFO: Completed Python level compilation and optimization. Nuitka:INFO: Generating source code for C backend compiler. Nuitka:INFO: Running data composer tool for optimal constant value handling. Nuitka:INFO: Running C compilation via Scons. Nuitka-Scons:INFO: Backend C compiler: clang (clang). Nuitka-Scons:INFO: Backend linking program with 10 files (no progress information available). Nuitka-Scons:WARNING: You are not using ccache. Nuitka-Postprocessing:INFO: Creating single file from dist folder, this may take a while. Nuitka-Onefile:INFO: Running bootstrap binary compilation via Scons. Nuitka-Scons:INFO: Onefile C compiler: clang (clang). Nuitka-Scons:INFO: Onefile linking program with 1 files (no progress information available). Nuitka-Scons:WARNING: You are not using ccache. Nuitka-Onefile:INFO: Keeping onefile build directory 'dist/test1.onefile-build'. Nuitka-Onefile:INFO: Using compression for onefile payload. Nuitka-Onefile:INFO: Onefile payload compression ratio (31.25%) size 17042132 to 5324924. Nuitka:INFO: Keeping dist folder 'dist/test1.dist' for inspection, no need to use it. Nuitka:INFO: Keeping build directory 'dist/test1.build'. Nuitka:INFO: Successfully created 'dist/test1.bin'. project@freebsd13:~/workspace/Pyfputs % ls build dist fputs.egg-info fputsmodule.c install.txt setup.py test1.py write.txt project@freebsd13:~/workspace/Pyfputs % cd dist/ project@freebsd13:~/workspace/Pyfputs/dist % ls fputs-1.0.0-py3.9-freebsd-13.1-RELEASE-p2-amd64.egg test1.dist test1.bin test1.onefile-build test1.build project@freebsd13:~/workspace/Pyfputs/dist % ls -rtlh total 5347 -rw-r--r-- 1 project project 5.5K Oct 15 10:17 fputs-1.0.0-py3.9-freebsd-13.1-RELEASE-p2-amd64.egg drwxr-xr-x 3 project project 23B Oct 15 10:59 test1.build drwxr-xr-x 2 project project 59B Oct 15 10:59 test1.dist drwxr-xr-x 3 project project 7B Oct 15 10:59 test1.onefile-build -rwxr-xr-x 1 project project 5.2M Oct 15 11:00 test1.bin project@freebsd13:~/workspace/Pyfputs/dist % ./test1.b test1.bin* test1.build/ project@freebsd13:~/workspace/Pyfputs/dist % ./test1.b ./test1.b: Command not found. project@freebsd13:~/workspace/Pyfputs/dist % ./test1.bin Python interface for the fputs C library function fputs Real Python!
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
标签:
python
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2019-10-15 thymeleaf中switch case多出一个空行
2019-10-15 使用MockMvc进行springboot调试(SpringbootTest)
2019-10-15 Lombok子类与父类的@Builder注解冲突
2019-10-15 thymeleaf自定义属性