Python:使用Pyinstaller 打包成exe文件

本文介绍了如何使用Pyinstaller将Python代码打包成可执行的exe文件,详细讲解了Pyinstaller的安装、基本命令用法,并通过一个Tkinter倒计时GUI程序示例,演示了不同参数下的打包过程,包括带控制台和不带控制台的打包方式,以及如何设置图标和修改生成的exe文件名。
摘要由CSDN通过智能技术生成

一、准备工作

  • Pyinstaller可以将Python的代码打包成可执行文件(.exe),打完包的可执行文件可在没有安装Python环境的PC上运行。
  • Python 3.7
  • 安装Pyinstaller:pip install pyinstaller
  • 使用文档:https://pyinstaller.readthedocs.io/en/stable/usage.html

二、Pyinstaller 命令介绍

  • 语法:pyinstaller [options] script [script …] | specfile
    如:pyinstaller XXX.py
  • 查看帮助:pyinstaller -h 或 pyinstaller --help
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
                  [--add-data <SRC;DEST or SRC:DEST>]
                  [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR]
                  [--hidden-import MODULENAME]
                  [--additional-hooks-dir HOOKSPATH]
                  [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
                  [--key KEY] [-d [{all,imports,bootloader,noarchive}]] [-s]
                  [--noupx] [-c] [-w]
                  [-i <FILE.ico or FILE.exe,ID or FILE.icns>]
                  [--version-file FILE] [-m <FILE or XML>] [-r RESOURCE]
                  [--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
                  [--win-no-prefer-redirects]
                  [--osx-bundle-identifier BUNDLE_IDENTIFIER]
                  [--runtime-tmpdir PATH] [--bootloader-ignore-signals]
                  [--distpath DIR] [--workpath WORKPATH] [-y]
                  [--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
                  scriptname [scriptname ...]

positional arguments:
 scriptname            name of scriptfiles to be processed or exactly one
                       .spec-file. If a .spec-file is specified, most options
                       are unnecessary and are ignored.

optional arguments:
 -h, --help            show this help message and exit
 -v, --version         Show program version info and exit.
 --distpath DIR        Where to put the bundled app (default: .\dist)
 --workpath WORKPATH   Where to put all the temporary work files, .log, .pyz
                       and etc. (default: .\build)
 -y, --noconfirm       Replace output directory (default:
                       SPECPATH\dist\SPECNAME) without asking for
                       confirmation
 --upx-dir UPX_DIR     Path to UPX utility (default: search the execution
                       path)
 -a, --ascii           Do not include unicode encoding support (default:
                      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值