• FreeBSD下开发Python插件并使用nuitka打包


    承接前面的文章

    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!
  • 相关阅读:
    【转】IntelliJ IDEA2017.3激活
    【转】构建Maven项目自动下载jar包
    【转】Intellij idea 的maven项目如何通过maven自动下载jar包
    【转】在IDEA中创建maven项目
    【转】maven的安装、配置以及下载jar包
    【转】git修改文件后,提交到远程仓库
    基于MbedTLS的AES加密实现,含STM32H7和STM32F4的实现例程
    Cortex-M7,A8,A9,A15与ADI的BlackFin以及SHARC的DSP性能PK
    基于V6的中移动物联测试例子,当前测试还挺稳定
    中移动物联手机端APP软件
  • 原文地址:https://www.cnblogs.com/passedbylove/p/16793735.html
Copyright © 2020-2023  润新知