坐看云起时|

一枚码农

园龄:7年6个月粉丝:5关注:1

python打包工具-Nuitka

nuitka将python源码转成C++(这里得到的是二进制的pyd文件,防止了反编译),然后再编译成可执行文件。提高安全性和运行速度。

github:https://github.com/2267770481/cython_test

安装

pip install nuitka
pip install ordered-set # 加速编译
pip install zstandard # onefile时压缩文件

打包

目录结构
image
代码地址:https://files.cnblogs.com/files/yimeimanong/cython_test.zip?t=1682506730&download=true

windows下打包
python -m nuitka --standalone --show-memory --show-progress --nofollow-imports --plugin-enable=numpy --follow-import-to=apps --output-dir=out --windows-icon-from-ico=./favicon.ico app.py

执行结果:
image

等打包完后,会生成个out文件夹,里边的app.dist就是我们需要的东西。
image

如果直接运行 app.dist/app.exe 程序的时候,有时候会出现缺少某个模块的情况,这是因为我们只将自己的代码转成C++,不管这些大型的第三方包!。所以我们需要在python依赖包文件夹(Lib\site-packages)中找到这些包,并复制到app.dist中。(比较懒的做法是将site-packages中的所有文件直接复制到app.dist中,如果有出现冲突的就选择跳过)

现在可以直接运行app.exe应用程序。
image

接口调用
http://127.0.0.1:1111/module_a/a_a
image

linux 和 mac也可以用上边的指令

指令集

--mingw64 #默认为已经安装的vs2017去编译,否则就按指定的比如mingw(官方建议)
--standalone 独立环境,这是必须的(否则拷给别人无法使用) 不需要再安装python等之类的
--windows-disable-console 没有CMD控制窗口
--output-dir=out 生成exe到out文件夹下面去
--show-progress 显示编译的进度,很直观
--show-memory 显示内存的占用
--nofollow-imports:不编译代码中所有的import,比如keras,numpy之类的。
--follow-import-to=utils,src:需要编译成C++代码的指定的2个包含源码的文件夹,这里用,来进行分隔。
--enable-plugin=pyside6
--plugin-enable=tk-inter 打包tkinter模块的刚需
--plugin-enable=numpy 打包numpy,pandas,matplotlib模块的刚需
--plugin-enable=torch 打包pytorch的刚需
--plugin-enable=tensorflow 打包tensorflow的刚需
--windows-icon-from-ico=你的.ico 软件的图标
--windows-company-name=Windows下软件公司信息
--windows-product-name=Windows下软件名称
--windows-file-version=Windows下软件的信息
--windows-product-version=Windows下软件的产品信息
--windows-file-description=Windows下软件的作用描述
--windows-uac-admin=Windows下用户可以使用管理员权限来安装
--windows-disable-console:运行exe取消弹框。这里没有放上去是因为我们还需要调试,可能哪里还有问题之类的。
--linux-onefile-icon=Linux下的图标位置
--onefile 单文件打包
–-remove-output 在打包结束后,清理打包过程中生成的临时文件
--include-package=复制比如numpy,PyQt5 这些带文件夹的叫包或者轮子
--include-module=复制比如when.py 这些以.py结尾的叫模块

本文作者:一枚码农

本文链接:https://www.cnblogs.com/yimeimanong/p/17356034.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   一枚码农  阅读(1156)  评论(0编辑  收藏  举报
 
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Sold Out Hawk
  2. 2 光辉岁月 Beyond
Sold Out - Hawk
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Jon Steingard

作曲 : Jon Steingard

I ain't like no one you met before

I'm running for the front

When they're all running for the door

And I won't sit down won't back out

You can't ever shut me up

Cause I'm on a mission

And I won't quit now

In a world full of followers

I'll be a leader

In a world full of doubters

I'll be a believer

I'm stepping out without a hesitation

Because the battle's already been won

I'm sold out

I'm no longer living

Just for myself

Running after Jesus

With my whole heart

And now I'm ready to show

I am sold out

I'm sold out

With every single

Step that I take now

With every drop of blood

Left in my veins

I'm gonna be making it count

I am sold out

This ain't just some temporary phase

You can't face this kind of grace

And leave the way you came

This is permanent with intent

And there won't be no stopping it now

I'm on a mission and it's heaven sent

In a world full of followers

I'll be a leader

In a world full of doubters

I'll be a believer

I'm stepping out without a hesitation

Cause my soul is like a stadium

I'm sold out

I'm no longer living

Just for myself

Running after Jesus

With my whole heart

And now I'm ready to shout

I am sold out

I'm sold out

With every single

Step that I take now

With every drop of blood

Left in my veins

I'm gonna be making it count

I am sold out

No trials coming against me

Could put a dent in my passion

They're just an opportunity

To put my faith into action

In a world full of followers

I'll be a leader

In a world full of doubters

I'll be a believer

I'm stepping out without a hesitation

I ain't got nothing left to be afraid of

I'm sold out

I'm no longer living

Just for myself

Running after Jesus

With my whole heart

And now I'm ready to show

I am sold out

I'm sold out

With every single

Step that I take now

With every drop of blood

Left in my veins

I'm gonna be making it count

I am sold out