Python 打包工具对比,Nuitka vs Pyinstaller

工具对比

Nuitka

Nuitka直接将python编译成C++代码 ,再编译C++代码产生可执行文件,彻底不存在反向解析的问题,很是安全,并且因为可执行文件由C++编译而来,运行速度也会得到提高。html

PyInstaller

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

软件安装 & 使用

测试文件

文件名:hello.pygit

代码内容:github

#!/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). 复制代码

解决方案:bash

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…
相关文章
相关标签/搜索