Easy Python compilation with NUITKA-Utilities

I found a good one

NUITKA-Utilities

https://github.com/Nuitka/NUITKA-Utilities

exe-maker.jpg

If you specify the .py file and the output folder, Nuitka will compile it for you. (exe-maker.py)

For Windows, install Mingw-w64 and PySimpleGUI in advance.

conda install m2w64-gcc libpython

pip install nuitka

pip install pysimplegui

Nuitka's standalone has a lot of dlls

Just specify the compiled .dist folder and it will create a single exe file. (Onefile-maker-windows.py)

onefile.png

Install NSIS on Windows in advance.

https://nsis.sourceforge.io/Download

I want to reduce the size

Use hinted-compilation. (It will not work as of the end of 2019)

https://github.com/Nuitka/NUITKA-Utilities/tree/master/hinted-compilation

When you run get-hints.py, it will pick up only the libraries you need. The size and compile time will be shorter.

I compared it with PyInstaller

I compared it with a handmade python script with GUI of about 60 lines.

test.py



# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.13.1
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets
import time

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(300, 200)
        MainWindow.setMaximumSize(QtCore.QSize(300, 200))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(100, 130, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(100, 50, 50, 12))
        self.label.setObjectName("label")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 300, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "Start"))
        self.label.setText(_translate("MainWindow", "Time:"))

        self.pushButton.pressed.connect(calc)

def calc():
    start = time.time()
    i = 10000000
    while i >= 0:
        i = i - 1
    stop = time.time()
    ui.label.setText(str(stop - start))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
PyInstaller NUITKA(-Utilities)
Single exe size 34.8MB 17.1MB
Execution result 0.8277249s 0.7182800s
Start-up Slightly slow slow

It's a pity that it takes a while to start, but the size is half. Since it is a compiled binary, the execution speed is a little fast. It took 55 seconds to compile on my PC and 43 seconds to create a single exe. pyinstaller made a single exe in about 20 seconds.

bonus

When I run nuitka from the command line, I wonder how to add options.

First, if you remove all the libraries, compile, and execute the created executable file, you will be scolded that the library is insufficient, so if you add it as appropriate, it will be completed someday.

python -m nuitka hoge.py --standalone --recurse-none --remove-output

Since hoge.exe is created in hode.dist, execute it on the command line.

The error that is returned is different in how to add options.

At the time of Warning, add --plugin-enable = and --recurse-to =. Qt and numpy are of this type. --plugin-enable=qt-plugins --recurse-to=PyQt5 --plugin-enable=numpy --recurse-to=numpy

When ModuleNotFoundError, add only --recurse-to =. Pyserial and OpenCV are this type. --recurse-to=serial --recurse-to=cv2

If you can start it happily, you can reduce the distribution size by checking and deleting unnecessary dlls. For example, if you use Qt as a GUI library, you can delete the Tcl and Tk dlls. If you don't use the network, you can delete the SSL and socket dlls.

Recommended Posts

Easy Python compilation with NUITKA-Utilities
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Python compilation with pyqt deploy
Easy HTTP server with Python
[Python] Easy parallel processing with Joblib
Easy Python + OpenCV programming with Canopy
Easy email sending with haste python3
Easy data visualization with Python seaborn.
Easy parallel execution with python subprocess
Easy modeling with Blender and Python
FizzBuzz with Python3
Easy keyword extraction with TermExtract for Python
Scraping with Python
[Python] Super easy test with assert statement
[Python] Easy argument type check with dataclass
Python is easy
Statistics with python
Scraping with Python
Python with Go
Integrate with Python
Easy introduction of speech recognition with Python
AES256 with python
Tested with Python
python starts with ()
[Easy Python] Reading Excel files with openpyxl
with syntax (Python)
Easy web app with Python + Flask + Heroku
Bingo with python
Zundokokiyoshi with python
Easy image processing in Python with Pillow
[Easy Python] Reading Excel files with pandas
Easy web scraping with Python and Ruby
[Python] Easy Reinforcement Learning (DQN) with Keras-RL
Excel with Python
Microcomputer with Python
Cast with python
[Python] Easy introduction to machine learning with python (SVM)
Csv output from Google search with [Python]! 【Easy】
Easy Lasso regression analysis with Python (no theory)
Make your Python environment "easy" with VS Code
✨ Easy with Python ☆ Estimated elapsed time after death ✨
Serial communication with Python
Zip, unzip with python
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Easy Grad-CAM with pytorch-gradcam
Scraping with Python (preparation)
Try scraping with Python.
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learn Python with ChemTHEATER
Run prepDE.py with python3
Collecting tweets with Python
3. 3. AI programming with Python
Kernel Method with Python