python打包工具优缺点对比
python打包工具优缺点对比
PyInstaller
优点
缺点
cx_Freeze
优点
缺点
Nuitka
优点
缺点
py2exe(仅适用于 Windows)
优点
缺点
https://zhuanlan.zhihu.com/p/463597594
文档
PyInstaller文档比Nuitka文档更加详细,条理性要更胜一筹。Nuitka文档中写的英语不是很标准,有语法错误,有时候会比较难看懂作者想要表达的意思 (作者本人不是以英语为母语的,所以可以理解吧)。
流行度
PyInstaller出来时间比Nuitka早,在国内流行程度也比较高 (国外不清楚)。通过百度搜索的结果数量可以知道目前PyInstaller被使用地更多。当然光从这一点上比较会不准确,大家可以从其他平台搜索结果上再比较下。
安全性
PyInstaller在打包时将py文件编译成pyc文件
,这个可以直接被反编译。你也可以通过--key命令在打包时进行加密,但也不安全。如果要做到更高程度的安全性,可以结合Cython来加密打包。Nuitka是直接将py文件编译成c语言级别的文件,安全性上面更胜一筹。
打包速度
对于简单的程序,两者的打包速度都是差不多的。不过碰到一个相对来说较大的库时,Nuitka会去编译这个库,导致它的打包速度非常非常非常地慢。当然,第三方库的代码是不需要加密的,所以我们可以通过--nofollow-imports命令不编译引入的库,通过--include-data-dir命令直接复制进来(当然你也可以后期手动复制)。PyInstaller默认是直接复制进来的,不会进行编译。
https://medium.com/@mpyatishev/python-on-the-go-pyinstaller-and-nuitka-d76e18650763
The conclusions from my experience with PyInstaller and Nuitka are as follows:
- Both solutions work without special rituals, which is good. True, there were difficulties with the application’s static files, but this is a shortcoming of the application itself, not PyInstaller or Nuitka.
- During the development stage, it is essential to make the right decision about where the data files and other static files will be stored and how they will be packaged or delivered to users.
- Regarding build speed, PyInstaller significantly outperforms Nuitka. It is understandable — PyInstaller does not recompile the entire application and its dependencies but simply moves them to the target directory. Build time is important when building pipelines.
- In terms of the size of the resulting directories/files, PyInstaller also outperforms Nuitka, although not significantly. This difference may not be as noticeable on larger projects.
https://sparxeng.com/blog/software/python-standalone-executable-generators-pyinstaller-nuitka-cx-freeze
Build Examples
The following command can be used to create a one-folder executable for the Python program defined in the Example Program section:
- cmd> python -m PyInstaller main.py
This command is used to generate a one-folder executable name “main” (based on the name of the python module supplied at build-time) which is placed inside of the default distribution folder location of “dist”. Note that the names and locations of the files/folders can be modified if desired (see the official Options documentation page for more details).
The generated one-file folder can then be compressed to a zip folder and transferred to another machine. Users will then have to unzip the folder and launch the executable found within to use the application.
Now let’s use a slightly more complex build command:
- cmd> python -m PyInstaller -F -w main.py
Here the “-F” argument is used to specify that a one-file executable is to be generated, and “-w” is used to indicate that a terminal window is not to be shown whenever the application starts (note that this is specific to Windows platforms). A one-file executable name “main” will be generated and placed in the default folder location of “dist”. This single application file can then be transferred to another machine and users will only have to execute it to use the application.