MediaPipe 在 Windows 上 import 报 ImportError: DLL load failed 怎么解决?
【免费下载链接】mediapipeCross-platform, customizable ML solutions for live and streaming media.项目地址: https://gitcode.com/GitHub_Trending/med/mediapipe
在 Windows 上通过pip install mediapipe装好 MediaPipe Python 包后,启动 Python 解释器执行import mediapipe as mp时,可能出现这样的报错:
ImportError: DLL load failed: The specified module could not be found这篇内容对应 MediaPipe 官方 troubleshooting 文档中的 "Python DLL load failure on Windows" 一节,说明这个报错的成因和官方给出的两种解决办法。适用前提是:MediaPipe Python 包来自 PyPI,官方支持的 Windows 环境为 amd64 Windows 上的 64 位 Python(docs/getting_started/troubleshooting.md 中 "Python pip install failure" 一节列出的支持范围为 x86_64 Linux、x86_64 macOS 10.15+ 和 amd64 Windows)。
先确认是这一类报错
这个报错发生在import 阶段,而不是pip install mediapipe阶段:包已经装上了,但 Python 加载其中的本地库时找不到所需的 DLL。报错信息以文档原文为准:
ImportError: DLL load failed: The specified module could not be found如果你遇到的是No matching distribution found for mediapipe,那属于 pip 安装阶段的系统/Python 版本不受支持问题,不在本文范围内(见文末"和相近报错的区分")。
原因
官方文档的结论是:该报错通常表示本地 Windows 系统缺少 Visual C++ redistributable 包和/或 Visual C++ 运行时 DLL。MediaPipe Python 包依赖这些运行时组件,系统里缺失时 import 就会在加载本地库这一步失败。
方案一:安装 Microsoft 官方 Visual C++ 可再发行组件包
官方文档给出的第一种解决方式是安装 Microsoft 官方的vc_redist.x64.exe(链接指向 Microsoft 官方的 "The latest supported Visual C++ downloads" 页面,可从 docs/getting_started/troubleshooting.md 原文查看下载地址)。
这是对系统的影响:在 Windows 系统层面安装 Visual C++ 运行时环境,属于一次性修复,装完后不需要改动任何 MediaPipe 配置。
方案二:通过 pip 安装 msvc-runtime 包(替代路径)
如果不想安装系统级的 redistributable 安装包,官方文档给出的替代方式是在 Python 环境中安装 "msvc-runtime" 包:
python -m pip install msvc-runtime注意文档的明确说明:"msvc-runtime" 这个 Python 包不是由 Microsoft 发布或维护的。选择哪种方案由你按环境自行决定,文档并列给出、未做优先级排序。
验证修复结果
无论采用哪种方案,修复完成后重新执行之前失败的 import 即可验证。MediaPipe Python 文档(docs/getting_started/python.md)展示的正常用法就是:
import mediapipe as mp mp_face_mesh = mp.solutions.face_mesh之前在这一步抛出ImportError: DLL load failed的,修复后应能正常完成 import 并成功取到mp_face_mesh,不再出现该报错。
和相近报错的区分
troubleshooting 文档中还有两条容易混淆的条目,对照可以避免走错方向:
ERROR: Could not find a version that satisfies the requirement mediapipe/ERROR: No matching distribution found for mediapipe:出现在pip install mediapipe阶段,表示当前系统或 Python 版本不在 PyPI 官方支持范围(64 位 Python + x86_64 Linux / x86_64 macOS 10.15+ / amd64 Windows)。文档建议核对 Python 与 pip 的版本,或按 python.md 中的 "Building MediaPipe Python Package" 从源码构建。ImportError: No module named numpy:缺少 Python 依赖包,按文档用pip install或pip3 install安装对应包即可,与 DLL 问题无关。
如果确认报错就是ImportError: DLL load failed: The specified module could not be found,按上面方案一或方案二处理后重新 import 验证即可;详细条目见 docs/getting_started/troubleshooting.md 的 "Python DLL load failure on Windows" 一节。
【免费下载链接】mediapipeCross-platform, customizable ML solutions for live and streaming media.项目地址: https://gitcode.com/GitHub_Trending/med/mediapipe
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考