likes
comments
collection
share

Python 打包工具对比,Nuitka vs Pyinstaller

作者站长头像
站长
· 阅读数 54

工具对比

Nuitka

Nuitka直接将python编译成C++代码 ,再编译C++代码产生可执行文件,完全不存在反向解析的问题,非常安全,而且由于可执行文件由C++编译而来,运行速度也会获得提升。

PyInstaller

PyInstaller可以用来打包python应用程序,打包完的程序就可以在没有安装Python解释器的机器上运行了。PyInstaller支持Python 2.7和Python 3.3+。可以在Windows、Mac OS X和Linux上使用,但是并不是跨平台的,而是说你要是希望打包成.exe文件,需要在Windows系统上运行PyInstaller进行打包工作;打包成mac app,需要在Mac OS上使用。

软件安装 & 使用

测试文件

文件名:hello.py

代码内容:

#!/bin/env python
print 'hello world!'

Nuitka

安装

# 本地安装
mkdir nuitka_source && cd nuitka_source
git clone https://github.com/Nuitka/Nuitka.git ./
python setup.py install

使用

# 编译单个文件
nuitka ./hello.py

# 编译某个目录的所有文件
nuitka ./hello.py  --include-plugin-directory=./ --remove-output --output-dir=./output -o ./output/hello

--include-plugin-directory: 编译依赖的目录
--remove-output: 移除编译输出的中间态文件
--output-dir: 指定输出信息的文件目录
-o: 指定输出的文件名(需包含所在目录)

PyInstaller

安装

# pip 方式安装
pip install pyinstaller

# pip 方式更新
pip install --upgrade pyinstaller

# 本地安装
mkdir pyinstaller_source && cd pyinstaller_source
git clone https://github.com/pyinstaller/pyinstaller.git ./
python setup.py install

使用

pyinstaller -F ./hello.py

遇到的问题

  1. 开发机上安装完 pyinstaller 工具之后,执行产出的编译文件,会报错,报错信息如下:
Floating point exception (core dumped)

网上查资料是因为系统版本不符导致,具体参考: github.tiankonguse.com/blog/2017/0…

  1. 使用 nuitka 工具时,因为开发机默认的gcc版本过低,导致报错,报错信息如下:
Input: nuitka hello.py
Nuitka:WARNING:Not recursing to 'log_parser' (/home/work/wangming/code/videoae/script_offline/uniondata/log_parser.py), please specify --nofollow-imports (do not warn), --follow-imports (recurse to all), --nofollow-import-to=log_parser (ignore it), --follow-import-to=log_parser (recurse to it) to change.
Nuitka:WARNING:Not recursing to 'field_dict' (/home/work/wangming/code/videoae/script_offline/uniondata/field_dict.py), please specify --nofollow-imports (do not warn), --follow-imports (recurse to all), --nofollow-import-to=field_dict (ignore it), --follow-import-to=field_dict (recurse to it) to change.
Nuitka:WARNING:Not recursing to 'colored_cli' (/home/work/wangming/code/videoae/script_offline/uniondata/colored_cli.py), please specify --nofollow-imports (do not warn), --follow-imports (recurse to all), --nofollow-import-to=colored_cli (ignore it), --follow-import-to=colored_cli (recurse to it) to change.
The gcc compiler gcc (version 3.4.5) doesn't have the sufficient version (>= 4.4).


解决方案:

export PATH=/opt/compiler/gcc-4.8.2/bin:$PATH

参考资料:

  1. www.twblogs.net/a/5b879b592…
  2. blog.csdn.net/qwemicheal/…
  3. www.helplib.com/GitHub/arti…
转载自:https://juejin.cn/post/6844903871622414343
评论
请登录