<>Python Generate executable file exe
<> one , install pyinstaller
pip install pyinstaller
<> two , use pyinstaller command
<> Use examples
* Relative path
In the program directory , Run command pyinstaller myscript.py
You can generate two folders in the current directory dist and build,exe File in dist Folder .
* Absolute path
In the program directory , Run command pyinstaller C:\myscript.py
Is generated in the directory where the command is currently executed dist and build folder
<> Common command parameters
* -F Specifies that only one is generated after packaging exe Format file
as :pyinstaller -F T1.py
be dist There is only one file exe Format file T1
* -i Change the generation process icon Icon
pyinstaller -F -i ./my.ico T1.py
* -n NAME,–name=NAME Set the name of the generated file (mypy)
pyinstaller -F -n mypy -i ./my.ico T1.py
<> three , When packing multiple files
* Existing package , Master file :pyinstaller -F main.py -p ./tools
* There is no bag , however py Time :pyinstaller -F main.py -p getexcel.py
<> supplement
* -c, –console, –nowindowed Using the console , No interface ( default )
* -w, –windowed, –noconsole Using Windows , No console
<> common problem
* routing problem : use pyinstaller When packing , If used rootPath =
os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
Then it will exe The path in the packing process is packed in , have access to os.path.dirname(os.path.realpath(sys.argv[0]))
Get the current run py, current path
Technology