PaddleSeg图像分割预测pyinstaller打包报错:No module named ‘framework_pb2‘,问题解决

45 篇文章 9 订阅
9 篇文章 4 订阅

报错

        在使用PaddlePaddle的FastDeploy部署图像分割时,需要验证目标电脑环境,所以先将预测代码predict.py用pyinstaller打包来试试,指令:

pyinstaller -D predict.py

         打包完成,成功生成exe

         运行时报错如下:

Traceback (most recent call last):
  File "paddle\fluid\ir.py", line 24, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module>
ModuleNotFoundError: No module named 'framework_pb2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "predict.py", line 18, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\__init__.py", line 57, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\__init__.py", line 15, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\spawn.py", line 24, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\utils.py", line 28, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\fleet\__init__.py", line 20, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\fleet\base\fleet_base.py", line 31, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\ir.py", line 28, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module>
ModuleNotFoundError: No module named 'framework_pb2'
[11528] Failed to execute script 'predict' due to unhandled exception!

核心问题就是:ModuleNotFoundError: No module named 'framework_pb2'

找不到framework_pb2,参考网上的解决方法:

paddleocr infer_rec打包失败framework_pb2 · Issue #5326 · PaddlePaddle/PaddleOCR · GitHub

解决方法

1. 按照上面链接中提到的,修改image.py

然后重新用pyinstaller打包生成exe,运行发现还是报错,执行下面第2步。

 2. 继续按照上面链接中提到的,将site-packages/paddle/fluid/中的proto文件夹复制到生成的dist/paddle/fluid/下

 继续运行时,发现不会再提示No module named 'framework_pb2'。

3. 将模型文件、配置文件、图片等放到制定目录,然后命令行运行

predict.exe --config configs/quick_start/my_deeplabv3.yml --model_path output/best_model/model.pdparams --image_path data/C0402/JPEGImages/02.jpg --save_dir output/result

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
引用\[1\]:已解决paddleocr infer_rec打包framework_pb2,导包import framework_pb2 as framework__pb2 ,抛出异常import framework_pb2 as framework__pb2 ModuleNotFoundError: No module namedframework_pb2’ \[61332\] Failed to execute script ‘test1’ due to unhandled exception!的正确解决方法,亲测有效!!!。引用\[2\]:编译成exe文件执行后报错信息如下所示:import framework_pb2 as framework__pb2 ModuleNotFoundError: No module named 'framework_pb2' \[61332\] Failed to execute script 'test1' due to unhandled exception!报错翻译。引用\[3\]:解决办法,把python安装目录下的python.exe拷贝到和当前编译好的exe同一个目录 缺少proto的报错Traceback (most recent call last): File “paddle\fluid\ir.py”, line 23, in File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module File “paddle\fluid\proto\pass_desc_pb2.py”, line 16, in ModuleNotFoundError: No module namedframework_pb2’。 问题:ModuleNotFoundError: No module named 'framework_pb2' 回答: 这个错误通常是由于找不到名为'framework_pb2'的模块导致的。根据引用\[1\]和引用\[2\]的信息,可以尝试导入'framework_pb2'模块时使用别名framework__pb2解决这个问题。例如,可以使用以下导入语句来导入该模块:import framework_pb2 as framework__pb2。这种方法已经被证实是有效的。另外,根据引用\[3\]的信息,还可以尝试将python安装目录下的python.exe拷贝到与当前编译好的exe文件相同的目录中,以解决缺少proto的报错。这些方法都可以尝试来解决ModuleNotFoundError: No module named 'framework_pb2'的问题。 #### 引用[.reference_title] - *1* *2* [已解决ModuleNotFoundError: No module namedframework_pb2’ [61332] Failed to execute script ‘test...](https://blog.csdn.net/yuan2019035055/article/details/129431169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [PaddleOcr打包问题](https://blog.csdn.net/u013932564/article/details/126948826)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Color Space

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值