【笔记】Python打包成exe

目前比较常见的打包exe方法都是通过Pyinstaller来实现的,当然,这个库貌似也只有windows环境能用。

为什么要打包?

Python脚本无法在没有安装Python的机器上运行,只有将脚本打包成exe文件,才能在没有安装Python的电脑上使用。

安装Pyinstaller

首先我们要先安装Pyinstaller,直接在cmd使用pip命令.

pip install pyinstaller  # 官方源安装
pip install -i https://pypi.douban.com/simple/ pyinstaller #豆瓣源安装
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller #清华源安装

Pyinstaller打包步骤

1.cmd切换到python脚本目录
2.执行以下命令
pyinstall -i xxx.ico -n xxx -w -D main.py
  • 命令参考
3.特别说明

Python打包exe一般体积大而且运行奇慢,最好是在虚拟环境中打包,改虚拟环境只要需要的包即可。

有时候需要将数据一起打包

#按2中操作后,修改xxx.spec中的datas值datas =['fliename1','filename2']
pyinstaller xxx.spec
posted @ 2021-05-27 00:03  介个车车烫屁股  阅读(125)  评论(0)    收藏  举报