NUITKA-Utilities
https://github.com/Nuitka/NUITKA-Utilities
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
Just specify the compiled .dist folder and it will create a single exe file. (Onefile-maker-windows.py)
Install NSIS on Windows in advance.
https://nsis.sourceforge.io/Download
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 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.
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