1、安装pyinstaller
pip install pyinstaller
2、转换单个.py文件为exe格式
pyinstaller程序有很多参数,转换单个.py文件常用的参数:
-F, --onefile Create a one-file bundled executable. #转换单个文件
-w, --windowed, --noconsole # 转换时不出现黑窗口
Windows and Mac OS X: do not provide a console window
for standard i/o. On Mac OS this also triggers
building a Mac OS .app bundle. On Windows this option
is automatically set if the first script is a '.pyw'
file. This option is ignored on *NIX systems.
使用举例
pyinstaller.exe --onefile --noconsole calculator_simple.py
或
pyinstaller.exe -F -w calculator_simple.py
exe文件生成在dist目录下。
如果打包时想要自己设置图标,可以使用 --icon参数:
pyinstaller.exe --onefile --noconsole --icon="D:\workspace\icons\demo.ico" calculator_simple.py