pyinstaller将python程序转换为exe

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。