Windows 下与 torch 的兼容性问题:安装 torch 时出现 OSError [WinError 127] #15579
-
🔎 Search before asking
🐛 Bug (问题描述)您好,PaddleOCR 团队, 首先感谢你们开发了这么棒的 OCR 工具!我最近在项目中使用 PaddleOCR,大部分情况下都非常好用。不过,我在 Windows 环境下发现了一个与 torch 相关的兼容性问题,想跟你们反馈一下,希望能作为改进建议。 在 Windows 环境下,当环境中安装了 torch(比如 torch==2.6.0+cpu)时,直接导入 PaddleOCR 会报错: 但如果环境中没有安装 torch,或者先 import torch 再 from paddleocr import PaddleOCR,就不会有问题。问题可能是 albumentations 在检测到 torch 时尝试加载它,导致 Windows 下 DLL 加载失败。我已经找到了一些解决办法,但觉得这个情况可能会影响其他用户的使用体验,所以想提个建议。 我找到两种可行的解决办法: 如果项目不需要 torch,卸载它: 先导入 torch,再导入 PaddleOCR: 补充信息 🏃♂️ Environment (运行环境)操作系统:Windows 11 🌰 Minimal Reproducible Example (最小可复现问题的Demo)在 Windows 上创建一个虚拟环境(比如 python -m venv venv)。 |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
感谢反馈,针对这个bug,我们会评估修复,针对这个问题,建议统一使用推理框架进行模型推理会更优秀,比如使用onnxruntime或者tensorrt等推理框架,统一转成onnx或者tensorrt,针对paddleocr,我做了onnxruntime的推理对齐,可以参考:https://github.com/jingsongliujing/OnnxOCR |
Beta Was this translation helpful? Give feedback.
-
看样子是不打算修复这个bug了?能否打个补丁呢?或者手动修改albumentations的代码? |
Beta Was this translation helpful? Give feedback.
-
我也遇上相关问题了,我是在使用fastdeploy库和ultralytics库时发生这个问题,目前是同时需要两种不同的功能模块,无法统一使用推理框架,我想问下这方面是否打算修复呢? |
Beta Was this translation helpful? Give feedback.
-
我也遇到这个问题了,@JackWu002的第二种方法对我有效: |
Beta Was this translation helpful? Give feedback.
-
牛,解决了,官方还是需要重视一下这个问题的,我也是windows这个报错 |
Beta Was this translation helpful? Give feedback.
-
爱死你了,我终于解决这个问题了!!!我排列组合各种python、torch、CUDA、PaddlePaddle的版本,不是shm.dll就是cudnn_cnn64_9.dll加载失败,我都快放弃了,终于看到这个issue,加一行代码就解决,心情仿佛便秘了后拉十斤那么舒畅。 先导入 torch,再导入 PaddleOCR: |
Beta Was this translation helpful? Give feedback.
-
I had the same issue while trying to fine-tune PaddleOCR on my GPU. But I finally found a workaround (not clean, but it works 😅):
import numpy as np
import torch # <== this one
from albumentations.core.transforms_interface import BasicTransform After that, it just worked for me |
Beta Was this translation helpful? Give feedback.
我也遇到这个问题了,@JackWu002的第二种方法对我有效:
先导入 torch,再导入 PaddleOCR:
import torch
from paddleocr import PaddleOCR
ocr = PaddleOCR()