Python executable file conversion library comparison (py2exe, cx_freeze, pyinstaller)

Introduction

There are some libraries that convert to executable with python, but I didn't know which one to use after all, so I tried them all together.

The code used this time is https://github.com/nabehide/tryFreezing Is in

The following three libraries are compared.

environment

Python environment

verification code

Suppose you want to convert the following sample code (main.py) to an executable format.

main.py


import sys
from PyQt4 import QtGui  # , QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure


class UI(QtGui.QWidget):

    def __init__(self):
        super(UI, self).__init__()
        self.initUI()
        self.drawFigure()

    def initUI(self):
        # window setting
        self.setGeometry(50, 50, 500, 300)
        self.setWindowTitle('Window title')

        # figure setting
        self.fig = Figure()
        self.canvas = FigureCanvas(self.fig)
        self.axes = self.fig.add_subplot(111)
        layoutFigure = QtGui.QGridLayout()
        layoutFigure.addWidget(self.canvas, 0, 0)

        self.setLayout(layoutFigure)

    def drawFigure(self):
        x = range(100)
        y = range(100)
        self.axes.plot(x, y)
        self.canvas.draw()


def main():
    app = QtGui.QApplication(sys.argv)
    ui = UI()
    ui.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

result

PyInstaller couldn't run with 3.2 https://github.com/pyinstaller/pyinstaller/issues/2086 I put in 3.3 by referring to

$ pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

The following are compared as indicators that I personally emphasize.

py2exe PyInstaller cx_Freeze
version 0.6.9 3.3.dev0+483c819 4.3.4
file size[MB] 43.5 81.5 44.7
execution time[sec] 15 49 8
startup time[sec] 1 5 1

Pyinstaller (3.3) is large and time consuming, but it seems to be stable. Each library can be set in various ways when converting the executable format, so there seems to be room for improvement.

(There is also Article that challenged the small size and speed by changing the Python environment)

Addressed error

cx_Freeze

cx_Freeze.freezer.ConfigError: no file named sys (for module collections.sys)

Added "collection.abc" to the excludes options as in collections.sys error The sample script is here

Other things I want to verify

Recommended Posts

Python executable file conversion library comparison (py2exe, cx_freeze, pyinstaller)
Python executable file conversion module comparison 2
GUI (WxPython) executable file (pyInstaller) [Windows] in Python3
Comparison of Japanese conversion module in Python3
Library comparison summary to generate PDF with Python
Record when generating an executable file from Python code using pyinstaller on Mac (OSError: Python library not found: avoiding libpython3.7m.dylib, .Python, libpython3.7.dylib)