解决python打包ModuleNotFoundError报错问题

参考: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文件。

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值