Python写的代码打包成.exe可执行文件
1. 安装pyinstaller2. [在线生成icon](/)3. 打包命令 pyinstaller -i x.ico -F y.py4. 效果图5. windows上pyinstaller可能的报错及解决参考1. 安装pyinstaller
Pyinstaller 可以将 .py 文件打包成 windows 下可执行的 .exe 文件
pip install pyinstaller
注意,打包后也可以用自己喜欢的图片作为exe的图标;需要一个现成的.ico图片
2. 在线生成icon
3. 打包命令 pyinstaller -i x.ico -F y.py
pyinstaller -i x.ico -F y.py
其中:
-i: 表示要加载的图标(没有选择图标可以不用写)
x.ico:表示自己选择的图标名(没有选择图标可以不用写)
-F:表示打包成.exe可执行文件
-c:表示打包程序有窗口
y.py:表示你要打包的py文件
4. 效果图
图标用了我最喜欢的颖宝,效果图如下:
5. windows上pyinstaller可能的报错及解决
错误: WARNING: file already exists but should not: C:\…\…\…\Local\Temp_MEI165842\torchvision_C.cp37-win_amd64.pyd
解决:.spec 增加如下几行
for d in a.datas:if '_C.cp37-win_amd64.pyd' in d[0]:a.datas.remove(d)break
打包命令为:pyinstaller -F --onefile xxx.spec