Original article
Virtual environment installation pyinstaller
pip install pyinstaller
pack exe command :( There are a lot of specific orders online )
# pack 1 individual py file , And hide the execution window
pyinstaller -F -w main.py
# pack 1 individual py file (-F), And hide the execution window (-w), Replace exe Of ico Icon (-i img.ico)
pyinstaller -F -w -i img.ico main.py
The above packaging method will save various dependent libraries to folders as source files , Most of the time we still want only one exe file
Package all dependent libraries in the folder into exe Inside :
# Merge into one exe Inside (--onefile), Replace exe Icon (--icon=img.ico),py Source file (main.py), Hide execution (-w)
pyinstaller --onefile --icon=img.ico main.py -w
Be careful : When all dependent libraries are packaged into one exe in the future , And hidden in CMD There will be an error when executing in window mode , Cause the program to not work properly , So you need to use
import subprocess
cmd = ' Yours CMD command '
res = subprocess.call(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)