参考:https://blog.csdn.net/qq_38418314/article/details/113992201
首先安装pyinstaller
Pip install pyinstaller
pyinstaller比较重要的命令,-F,-D(默认方式,可不指定),-w
-F 把所有依赖的dll都打包到了exe中,缺点是启动巨慢,特别是依赖了深度学习框架等多种包后
-D 除了exe还会生成很多动态库,启动比-F方式要快很多,但是相比脚本执行,依然会慢很多(推荐使用)
-w 不弹出终端
问题:ModuleNotFoundError: No module named ‘face_alignment.detection’
解决方法:修改.spec文件
1.根据报错信息查看缺少的库所在位置
我的报错信息:
ModuleNotFoundError: No module named 'face_alignment.detection'
查看库的位置:
import face_alignment.detection
print(face_alignment.detection.__file__)
显示:
C:\Users\user_name\.conda\envs\py38\lib\site-packages\face_alignment\detection\__init__.py
2.使用记事本打开.spec文件,然后在文件中添加:
a.datas += Tree("C:/Users/user_name/.conda/envs/py38/lib/site-packages/face_alignment", prefix="face_alignment")
a.datas += Tree("C:/Users/user_name/.conda/envs/py38/lib/site-packages/face_alignment/detection", prefix="face_alignment.detection")
修改后如下图:
3.运行
pyinstaller xxx.spec
完成后即可正常运行dist下的exe文件。