首页 > 编程语言 >FreeBSD下开发Python插件并使用nuitka打包

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

时间:2022-10-15 11:12:37浏览次数:56  
标签:INFO test1 插件 dist upx Python -- FreeBSD 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="[email protected]",
          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!

 

标签:INFO,test1,插件,dist,upx,Python,--,FreeBSD,Nuitka
From: https://www.cnblogs.com/passedbylove/p/16793735.html

相关文章

  • [oeasy]python0007-Guido的简历
    Guido的简历......
  • [oeasy]python0007-Guido的简历
    ​ 执行esc退回到正常模式​编辑esc退出插入模式准备底行命令模式运行当前py文件保存执行​:w|!python3%​保存并用python3解释当前程序(%)​......
  • # yyds干货盘点 #怎么把这两行Python代码写成一行代码?
    大家好,我是皮皮。一、前言前几天在Python最强王者交流群【刘苏秦......
  • Python 图片亮度检测和调节
    项目上遇到一个问题,图片上的物体识别度较差,尤其是在晚上的图片,画面模糊不清晰,则需要对太暗的图片需要单独提高画面亮度。解法分2步:先检测画面亮度,然后调节画面亮度与对比度......
  • Python|conda重置环境
    前言一般情况下,个人在condabase环境下进行编码,有时新装的包乱了、或者错误的更新,欲重置回滚。或者是本地环境的包太多太杂了,需要回滚到初始状态。解决方案condalist-......
  • 怎么把这两行Python代码写成一行代码?
    大家好,我是皮皮。一、前言前几天在Python最强王者交流群【刘苏秦】问了一个Python的问题,提问截图如下:想法还是非常好的。二、实现过程这里【dcpeng】给了一个代码,不......
  • 2022-08-12-esp32把玩记-②_用Micropython点ssd1306_oled屏幕
    layout:postcid:8title:esp32把玩记-②用Micropython点ssd1306oled屏幕slug:8date:2022/08/1215:12:39updated:2022/08/1215:12:39status:publishautho......
  • 实用:python中命令调度分发器
    '''要求:程序员可以方便的注册函数到某个命令,用户输入命令时,路由到注册的函数,如果没有此命令,执行默认函数,用户输入input分析:输入命令映射到一个函数,并执行这个函数,应该c......
  • Python实验报告——第6章 函数
    实验报告【实验目的】 1.掌握如何创建并调用一个函数,以及如何进行参数传递和指定函数的返回值等。2.掌握变量的作用域和匿名函数。【实验条件】1.PC机或者远程编程......
  • Python Flask-SocketIO没有启动成功
    背景最近想做websocket服务端,发现Flask已提供第三方库;尝试使用后,发现前端也必须使用SocketIO,不太适用,所以放弃。 问题WARNINGininit:WebSockettransportnotavai......