python程序打包:pyinstaller

1、安装

pip install pyinstaller

2、创建单个可执行文件.exe:--onefile

pyinstaller --onefile your_project.py

3、增加配置文件:--add-data

ps:你的脚本如果用到了配置文件。

以我使用为例:我一个主程序test.py,一个日志配置文件log_config.py,还有一个config.json参数配置文件。

pyinstaller --onefile --add-data "log_config.py;." --add-data "config.json;." test.py

4、使用

直接将dist下的.exe移植双击使用好了。

5、建议

为你的脚本程序创建单独的虚拟环境,该环境仅仅安装你的脚本需要的库。


发表评论

评论列表,共 0 条评论

    暂无评论