pyinstaller parameter description and summary

Recent use tkinter + python + pyinstaller realized the project gadget, this record pyinstaller relevant parameters as well as to climb over the pit.

A, pyinstaller parameters

-F, -onefile pack a single file, if your code is written in a .py file, you can use this, if it is more than .py files do not use
-D, -onedir package multiple files in the dist generate a lot of dependent files, tools for writing code to form the framework, I personally recommend this, the code is easy to maintain
-K, -tk included in the deployment of TCL / TK
-a, -ascii does not include encoding. Unicode support on the python version the default includes all the coding.
-d, -debug generate debug version of the executable file
-w, -windowed, -noconsole use Windows subsystem execution. when the program starts does not open the command line (Windows only valid)
-c , -nowindowed, -console
using the console subsystem execution (default) (valid only for Windows)

PyInstaller -c xxxx.py

PyInstaller xxxx.py --console

-s, -strip executables and shared libraries will run through strip. The strip Cygwin attention often makes ordinary win32 Dll can not be used.
-X, -upx if UPX installation (detection execution Configure.py), will perform compression file (DLL Windows systems will also) (see note)
-o DIR, DIR = -out specified build directory spec file, if not specified, and the current directory is the root directory PyInstaller will automatically create one for output ( spec and resulting executable file) directory. If not specified, and the root directory of the current directory is not PyInstaller, it is output to the current directory.
-p the DIR, the DIR = -path introducing path disposed (and similar results using PYTHONPATH ) You can use a path delimiter (Windows use a semicolon, Linux use a colon) split, specify multiple directories. You can also use multiple -p parameter to set import multiple paths, so pyinstaller find their own program requires resources
-icon = <fILE.ICO>
will be added as a resource file.ico executable file (only valid for Windows systems), changing the program's icon pyinstaller -i ico path xxxxx.py

-Icon = <FILE.EXE, N> file.exe the n-th icon to add a resource executable file (only valid for Windows systems)
-v FILE, FILE = -version will verfile as the version of the executable file resources (only valid for Windows systems)
-n nAME, -name = nAME optional items (spec generated) name. If the primary file name is omitted, the first spec script as the name of the
two, pyinstaller climb pit summary

The first play pyinstaller, met a lot of pits, sum up here, so as not to fall into the pit again later.

1, starting with the writing tools to say it, write the original intention of this tool is due to their own hand-made data files took a long time, and then thinking about writing a tool to solve this problem (but also want the ability to exercise at their own code ha ha ha), in the evening after work and on weekends to write about a week to write out.

This tool is a scan code generation tool payment documents, mainly to solve handcrafted file data, there are two functions, one basic scan code file generation, and second, high-volume document generation scan code, while adding a user control auth.

Here to remind you, in your code inside try not to use import, energy from ..... import .... as much as possible with this, because if it is import, then packed in time, the entire package will have to pack inside exe , it does not make sense to increase the size of the tool!

Probably framework as follows:

 

2, after the completion of the development Gui, began to study pyinstaller, also read the forum related to usage of pyinstaller, I summarize here the tool packaging step

2.1, first download pyinstaller, I'm lazy, the direct use pip install pyinstaller, waiting for the automatic installation

2.2, carried out cmd in the path code, jump directly to the cmd interface that path, remember the path not to have Chinese

 

2.3, the first generation tool exe in background mode, command pyinstaller xxxx.py file, the main purpose is to see the error message, after solving the error, and then generate a complete version of the tool

tip: Since my code is dependent on the existence of that multi-file, but not all the code in one file, so I did not use -F here, just started to play when I do not know, always use the -F generating a single file without generating dependence, always unsuccessful, friends remember!

The figure below shows the command generated log, red frame part is the exe tool path generation, if only info message in the log, it indicates that there is no problem packing process

 

 

2.4, find the generated exe file, run the exe (exe files are generated in the dist directory)

 

Run-time, I encountered the following error message, is to find relevant images in dist resources, it is necessary to put all the resources on the tools needed (dependent contain pictures and .py files are placed in the project directory dist)

 

 

2.5, run again exe, is now running successfully, tools Packaging Success

 

2.6, rebuild the exe tool to remove and replace the lost icon background mode

I recommend an icon to get the address, which ico find many: easyicon

After downloading their favorite ico, with -i + ico path to replace the default ico, exe regenerate this tool, command pyinstaller -i ico path -w xxxx.py

 

And then takes a picture resources and code file into the project folder dist

 

2.7, run exe, be able to open it means pyinstaller packaged exe success


---------------------

Reference link: https: //blog.csdn.net/bearstarx/article/details/81054134

Guess you like

Origin www.cnblogs.com/xiohao/p/11094878.html