Python packaging exe tool experience

        The function development is almost done in the past few days. I want to improve the startup speed of the program after python packaging, because it feels too slow when starting up, it takes 6 seconds when it is slow, and 4 seconds when it is fast, but after some exploration, I found that there seems to be no tool to solve this problem. The essence is that the current packaging program usually packs the python interpreter into it, and then the program is finally interpreted and executed by python. When starting, it is equivalent to opening a python first, and then executing it with python The entry code, this link is essential, so you may not invest energy in this area later, if you want to change the language directly.

        In order to see if there is any solution, I tried two more packaging tools, one is nuitka, this tool is the only one with high hopes, because its packaging idea is to convert python code into c, optimize it, and then compile it into binary , From the perspective of thinking, it feels like converting python to c, but unfortunately, my project was not successfully packaged, and it took too long, and the official website said that the current support for pyqt5 is not complete, so Maybe even if the package is successful, I don’t know if it can run, and if there is a problem, I don’t know how to troubleshoot. In short, the compatibility of this tool is not very good, especially when your program relies on a lot of third packages. The most important thing is Yes, I packaged a simple pyqt5 program, and the startup speed of the final executable file did not improve much, so I finally gave up decisively.

        The second tool is cxfreeze. This tool is relatively simple to use. After I installed it, I packaged my project successfully without any configuration. The only problem is that the package is too large and there is a G, and this is in For the virtual environment, I used pyinstaller to package the same project, only more than 200 M.

        So, after these two days of trying, I think pyinstaller is the most fragrant, as long as it is in a virtual environment, it will not be too big after packaging. Of course, this requires you to be very clear about your project's dependence, which ones to use, and only the top layer. The package is fine, and the top-level dependencies will be installed automatically, so there is no need to record them.

        Another problem is that after testing, it is best not to enable upx when packaging the pyqt5 program, because upx is a compression tool. Although it will make the packaged file smaller, it will slow down the speed because it needs to be decompressed at startup. The project was reduced by about 100M after enabling upx compression, but the startup speed was significantly slower, so I finally turned it off.

        The speed problem is for the time being. If you want to optimize it later, you can only change to c# or cpp.

Guess you like

Origin blog.csdn.net/zy1620454507/article/details/127924602