本文使用创作助手。
pyinstaller是一个非常强大的打包工具,可以将Python脚本打包成独立的可执行文件。以下是pyinstaller的一些常用选项和用法:
- 打包一个Python脚本:
pyinstaller your_script.py
将"your_script.py"替换为你要打包的Python脚本的文件名。
- 打包成单个独立的可执行文件:
pyinstaller --onefile your_script.py
使用"--onefile"选项可以将所有依赖文件打包成一个单独的可执行文件。
- 指定生成文件的输出目录:
pyinstaller --distpath=output_directory your_script.py
使用"--distpath"选项可以指定生成的可执行文件的输出目录。
- 指定生成文件的名称:
pyinstaller --name=custom_name your_script.py
使用"--name"选项可以指定生成的可执行文件的名称。
- 包含额外的文件或目录:
pyinstaller --add-data "images;images" --add-data "music;music" your_script.py
使用"--add-data"选项可以指定额外需要打包的文件或目录。每个"--add-data"选项后面的参数格式为"source;destination",其中"source"是需要打包的文件或目录路径,"destination"是生成的可执行文件中的路径。
- 指定生成文件的图标:
pyinstaller --icon=icon.ico your_script.py
使用"--icon"选项可以指定生成的可执行文件的图标。
- 隐藏命令行窗口(仅适用于Windows):
pyinstaller --windowed your_script.py
使用"--windowed"选项可以隐藏生成的可执行文件的命令行窗口。
这些只是pyinstaller的一些常用选项和用法,你可以在命令行中执行"pyinstaller --help"命令查看所有可用选项。同时,你也可以查阅pyinstaller的官方文档以了解更多详细信息:https://pyinstaller.readthedocs.io/