源码

1、安装Pyinstallerpipinstallpyinstaller2、查找位置pyinstaller:pipshowpyinstaller3、找到路径设置环境变量:比如这个路径:C:\Users\。。。。\Python311\Scripts4、验证是否安装成功pyinstaller--version4、打包:dist文件夹:exe位置build文件夹:日志信息.spec文件:配置文件最简单的打包方式:pyinstallerchat_app.py常用打包:-w:隐藏控制台窗口-F:只生成一个exe-i:exe的图标pyinstaller-w-F-iicon.icochat_app.py也可以把打包的所有信息都写在配置文件里,然后直接运行:pyinstallermy_app_name.spec如果您的应用使用了数据库连接,可能需要在打包时包含数据库驱动程序。对于MySQL,您可能需要添加--add-binary参数:pyinstaller--onefile--windowed--add-data"path/to/your/assets;assets"--add-binary"path/to/mysql/lib;."chat_app.py打包为exe的话,版本尽量选择python3.6+32位版本,因为win64位系统向下兼容32位程序,但是如果不考虑32位系统的话无所谓,直接python64位版本直接打包就可以,只是只能在win64位系统上跑。--add-data--add-binary这个两个参数应该具体怎么设置,请给出示例封装示例:pyinstaller--onefile--windowed--add-binary"C:\path\to\mysql\lib\libmysql.dll;."chat_app.py配置文件封装:pyinstallerchat_app.spec--add-data"plotly;plotly":添加plotly库的数据文件--hidden-importplotly.graph_objs和--hidden-importplotly.subplots:添加可能未被自动检测到的导入安装anaconda,可以解决很多兼容性或文件缺失问题

2024-9-18 389 0
2021-10-2 999 0