Record the pits encountered in the packaging process of pyinstaller

The packaging process mainly refers to PyInstaller packaging details

Multithreading bug

No error is reported during the build process. After running the exe, an empty command line window pops up, and the task manager is called up to find that main.exe is constantly starting the process.
Insert picture description here
After you have reviewed pyinstaller document discovery may open the debug mode, the main.specfile is modified debug=True,and re

pyinstaller main.spec

Generate an executable file in debug mode, double-click to run main.exe and print out the command line, you can see that the program is exhausted and call mine repeatedly main.py.

[8828] PyInstaller Bootloader 3.x
[8828] LOADER: executable is E:\code\vision_sensor\dist\main\main.exe
[8828] LOADER: homepath is E:\code\vision_sensor\dist\main
[8828] LOADER: _MEIPASS2 is NULL
[8828] LOADER: archivename is E:\code\vision_sensor\dist\main\main.exe
[8828] LOADER: No need to extract files to run; setting extractionpath to homepath
[8828] LOADER: SetDllDirectory(E:\code\vision_sensor\dist\main)
[8828] LOADER: Already in the child - running user's code.
[8828] LOADER: Python library: E:\code\vision_sensor\dist\main\python37.dll
[8828] LOADER: Loaded functions from Python library.
[8828] LOADER: Manipulating environment (sys.path, sys.prefix)
[8828] LOADER: sys.prefix is E:\code\vision_sensor\dist\main
[8828] LOADER: Pre-init sys.path is E:\code\vision_sensor\dist\main\base_library.zip;E:\code\vision_sensor\dist\main
[8828] LOADER: Setting runtime options
[8828] LOADER: Initializing python
[8828] LOADER: Overriding Python's sys.path
[8828] LOADER: Post-init sys.path is E:\code\vision_sensor\dist\main\base_library.zip;E:\code\vision_sensor\dist\main
[8828] LOADER: Setting sys.argv
[8828] LOADER: setting sys._MEIPASS
[8828] LOADER: importing modules from CArchive
[8828] LOADER: extracted struct
[8828] LOADER: callfunction returned...
[8828] LOADER: extracted pyimod01_os_path
[8828] LOADER: callfunction returned...
[8828] LOADER: extracted pyimod02_archive
[8828] LOADER: callfunction returned...
[8828] LOADER: extracted pyimod03_importers
[8828] LOADER: callfunction returned...
[8828] LOADER: Installing PYZ archive with Python modules.
[8828] LOADER: PYZ archive: PYZ-00.pyz
[8828] LOADER: Running pyiboot01_bootstrap.py
[8828] LOADER: Running pyi_rth__tkinter.py
[8828] LOADER: Running pyi_rth_traitlets.py
[8828] LOADER: Running pyi_rth_pkgres.py
[8828] LOADER: Running pyi_rth_win32comgenpy.py
[8828] LOADER: Running pyi_rth_pyqt5.py
[8828] LOADER: Running pyi_rth_mplconfig.py
[8828] LOADER: Running pyi_rth_mpldata.py
[8828] LOADER: Running pyi_rth_multiprocessing.py
[8828] LOADER: Running main.py
[20904] PyInstaller Bootloader 3.x
[20904] LOADER: executable is E:\code\vision_sensor\dist\main\main.exe
[20904] LOADER: homepath is E:\code\vision_sensor\dist\main
[20904] LOADER: _MEIPASS2 is E:\code\vision_sensor\dist\main
[20904] LOADER: archivename is E:\code\vision_sensor\dist\main\main.exe
[20904] LOADER: SetDllDirectory(E:\code\vision_sensor\dist\main)
[20904] LOADER: Already in the child - running user's code.
[20904] LOADER: Python library: E:\code\vision_sensor\dist\main\python37.dll
[20904] LOADER: Loaded functions from Python library.
[20904] LOADER: Manipulating environment (sys.path, sys.prefix)
[20904] LOADER: sys.prefix is E:\code\vision_sensor\dist\main
[20904] LOADER: Pre-init sys.path is E:\code\vision_sensor\dist\main\base_library.zip;E:\code\vision_sensor\dist\main
[20904] LOADER: Setting runtime options
[20904] LOADER: Initializing python
[20904] LOADER: Overriding Python's sys.path
[20904] LOADER: Post-init sys.path is E:\code\vision_sensor\dist\main\base_library.zip;E:\code\vision_sensor\dist\main
[20904] LOADER: Setting sys.argv
[20904] LOADER: setting sys._MEIPASS
[20904] LOADER: importing modules from CArchive
[20904] LOADER: extracted struct
[20904] LOADER: callfunction returned...
[20904] LOADER: extracted pyimod01_os_path
[20904] LOADER: callfunction returned...
[20904] LOADER: extracted pyimod02_archive
[20904] LOADER: callfunction returned...
[20904] LOADER: extracted pyimod03_importers
[20904] LOADER: callfunction returned...
[20904] LOADER: Installing PYZ archive with Python modules.
[20904] LOADER: PYZ archive: PYZ-00.pyz
[20904] LOADER: Running pyiboot01_bootstrap.py
[20904] LOADER: Running pyi_rth__tkinter.py
[20904] LOADER: Running pyi_rth_traitlets.py
[20904] LOADER: Running pyi_rth_pkgres.py
[20904] LOADER: Running pyi_rth_win32comgenpy.py
[20904] LOADER: Running pyi_rth_pyqt5.py
[20904] LOADER: Running pyi_rth_mplconfig.py
[20904] LOADER: Running pyi_rth_mpldata.py
[20904] LOADER: Running pyi_rth_multiprocessing.py
[20904] LOADER: Running main.py
[3940] PyInstaller Bootloader 3.x
[3940] LOADER: executable is E:\code\vision_sensor\dist\main\main.exe
[3940] LOADER: homepath is E:\code\vision_sensor\dist\main
[3940] LOADER: _MEIPASS2 is E:\code\vision_sensor\dist\main
[3940] LOADER: archivename is E:\code\vision_sensor\dist\main\main.exe
[3940] LOADER: SetDllDirectory(E:\code\vision_sensor\dist\main)
[3940] LOADER: Already in the child - running user's code.
[3940] LOADER: Python library: E:\code\vision_sensor\dist\main\python37.dll
[3940] LOADER: Loaded functions from Python library.
[3940] LOADER: Manipulating environment (sys.path, sys.prefix)
[3940] LOADER: sys.prefix is E:\code\vision_sensor\dist\main
[3940] LOADER: Pre-init sys.path is E:\code\vision_sensor\dist\main\base_library.zip;E:\code\vision_sensor\dist\main
[3940] LOADER: Setting runtime options
[3940] LOADER: Initializing python
[3940] LOADER: Overriding Python's sys.path
[3940] LOADER: Post-init sys.path is E:\code\vision_sensor\dist\main\base_library.zip;E:\code\vision_sensor\dist\main
[3940] LOADER: Setting sys.argv
[3940] LOADER: setting sys._MEIPASS
[3940] LOADER: importing modules from CArchive
[3940] LOADER: extracted struct
[3940] LOADER: callfunction returned...
[3940] LOADER: extracted pyimod01_os_path
[3940] LOADER: callfunction returned...
[3940] LOADER: extracted pyimod02_archive
[3940] LOADER: callfunction returned...
[3940] LOADER: extracted pyimod03_importers
[3940] LOADER: callfunction returned...
[3940] LOADER: Installing PYZ archive with Python modules.
[3940] LOADER: PYZ archive: PYZ-00.pyz
[3940] LOADER: Running pyiboot01_bootstrap.py
[3940] LOADER: Running pyi_rth__tkinter.py
[3940] LOADER: Running pyi_rth_traitlets.py
[3940] LOADER: Running pyi_rth_pkgres.py
[3940] LOADER: Running pyi_rth_win32comgenpy.py
[3940] LOADER: Running pyi_rth_pyqt5.py
[3940] LOADER: Running pyi_rth_mplconfig.py
[3940] LOADER: Running pyi_rth_mpldata.py
[3940] LOADER: Running pyi_rth_multiprocessing.py
[3940] LOADER: Running main.py

Refer to the description in the official pyinstaller documentation.
When using multi-threaded modules multiprocessing, you must add code to the program entry

if __name__ == '__main__':
    # Pyinstaller fix
    multiprocessing.freeze_support()
    # 以下写主要代码
    main()

After this change, you can package and run the exe.

Guess you like

Origin blog.csdn.net/qq_26751117/article/details/97909308