python学习
1 python 库学习
1.1 pyinstaller
1.1.1 基本用法
1 | |
执行结果:生成两个文件夹(build,dist)以及一个 xxx. spec 文件
- dist 文件夹包含打包后的可执行文件
- build 文件夹包含打包过程中的临时文件
- .spec 文件是 pyinstaller 的配置文件
1.1.2 常用命令选项
| 选项 | 说明 | 示例命令 |
|---|---|---|
| –onefile 或 -F | 将所有依赖项打包成单个可执行文件,非常适合分发。 | pyinstaller –onefile your_script.py |
| –onedir 或 -D | 默认选项。生成一个包含可执行文件和所有依赖库的文件夹。启动速度通常比单文件模式快。 | pyinstaller –onedir your_script.py |
| –noconsole 或 -w | 运行可执行文件时不显示命令行控制台窗口,适用于 GUI 应用程序(如 PyQt, Tkinter 开发的应用)。 | pyinstaller –noconsole your_script.py |
| –icon= |
为生成的可执行文件设置自定义图标。需要提供 .ico 格式的图标文件。 | pyinstaller –icon=my_icon.ico your_script.py |
| –name= |
指定生成的可执行文件的名称,而不是使用脚本原名。 | pyinstaller –name=MyApp your_script.py |
| –add-data=”<SRC;DEST>” | 添加非代码资源文件(如图片、配置文件)。源路径和目标路径用分号分隔(Linux/macOS 用冒号)。 | pyinstaller –add-data=”config.ini;.” your_script.p y |
| –hidden-import= |
手动添加 PyInstaller 未能自动检测到的依赖模块。 | pyinstaller –hidden-import=pandas your_script.py |
| –exclude-module= |
排除不需要的模块,有助于减小生成文件的体积。 | pyinstaller –exclude-module=tkinter your_script.py |
python学习
https://www.moerjielovecookie.icu/2025/12/01/python学习/