one . pyinstaller and Nuitka Use feeling

1.1 Use requirements

This is also due to the needs of the project , Want to python Code conversion exe Procedure , After looking for it for a long time , Found it 2 Both can be right python Tools for project packaging ——pyintaller and nuitka.

this 2 Both tools can meet the needs of the project at the same time :

*

Hidden source code . there pyinstaller Yes by setting key To encrypt the source code ; and nuitka Will python Source code conversion C++( What we get here is binary pyd file , Decompilation is prevented ), Then compile it into an executable file .

*
Convenient transplantation . Convenient for users , No more installation python ah , Third party packages or something .

1.2 Use feeling

2 The biggest feeling after using a tool is :

pyinstaller Poor experience !

*
A deep learning project is finally turned into exe It's close 3 individual G Size of (pyinstaller Is to package the entire running environment ), yes , You heard me right , One EXE have 3 individual G!

*
Packing super slow , Start super slow .

nuitka Really fragrant !

*
Same project , Generated exe only 7M!

*
Packing super fast (1min within ), Start super fast .

two . Nuitka Installation and use of

2.1 nuitka Installation of

*
Direct utilization pip Ready to install :pip install Nuitka

*
download vs2019(MSVS) perhaps MinGW64, Anyway C++ Compiler for , Whatever .

2.2 Use process

For projects that rely on more packages from third parties ( Like need import
torch,tensorflow,cv2,numpy,pandas,geopy wait ) for , The best way to package here is to convert only your own code into C++, Regardless of these large third-party packages !

Here's me demo A directory structure for ( Used here pytq5 Framework written interface ):
├─utils// Source code 1 folder ├─src// Source code 2 folder ├─logo.ico//demo Icon for └─demo.py//main file
Use the following command ( debugging ) Direct generation exe file :

nuitka --standalone --show-memory --show-progress --nofollow-imports --plugin-enable=qt-plugins --follow-import-to=utils,src --output-dir=out --windows-icon-from-ico=./logo.ico demo.py
Here is a brief introduction to my above nuitka Command of :

*
--standalone: Easy to transplant to other machines , No more installation python

*
--show-memory --show-progress: Show the progress of the whole installation

*
--nofollow-imports: Do not compile all of the import, such as keras,numpy Something like that .

*
--plugin-enable=qt-plugins: I use it here pyqt5 To make the interface , here nuitka Has its corresponding plug-in .

*
--follow-import-to=utils,src: Need to compile into C++ Code specified 2 A folder containing source code , Use here , To separate .

*
--output-dir=out: Specifies that the output result path is out.

*

--windows-icon-from-ico=./logo.ico: Specify generated exe The icon for is logo.ico This icon , Here is a recommended way to turn the picture into ico Format file web site ( Bitworm ).

*
--windows-disable-console: function exe Cancel pop-up . We didn't put it here because we still need debugging , Maybe there's something wrong with it .

after 1min After compiling , You can see it in your directory :
├─utils// Source code 1 folder ├─src// Source code 2 folder ├─out// Generated exe folder     ├─demo.build      └─demo.dist
  └─demo.exe// Generated exe file ├─logo.ico//demo Icon for └─demo.py//main file
Of course, here you will find that the real operation exe When , Will report an error :no module named torch,cv2,tensorflow Wait, these didn't turn into C++ Third party package .

We need to find these bags here ( Mine is in software\python3.7\Lib\site-packages lower ) copy ( such as numpy,cv2 This folder ) reach demo.dist Under path .

thus ,exe It works perfectly ! Not yet. You can add friends to study together

Technology