posts - 570,  comments - 96,  views - 171万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

承接前面的文章

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!
复制代码

 

posted on   你不知道的浪漫  阅读(467)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 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自定义属性
点击右上角即可分享
微信分享提示