# 动态链接库(DLL)初始化例程失败


<!--more-->

> ImportError: DLL load failed while importing onnxruntime_pybind11_state: 动态链接库(DLL)初始化例程失败

场景：`python 3.10` 版本，使用 `MarkItDown v0.1.1` 时，报错 ==ImportError: DLL load failed while importing onnxruntime_pybind11_state: 动态链接库(DLL)初始化例程失败==[red]

``` shell {data-open=true}
# 卸载 GPU 和 CPU 版本避免冲突
pip uninstall onnxruntime -y
pip uninstall onnxruntime-gpu -y

# 清理 pip 缓存
pip cache purge

# 然后根据需要只装一个版本：
# 如果你要使用 GPU（CUDA 支持）
pip install onnxruntime-gpu==1.16.0

# 或者如果你只用 CPU
pip install onnxruntime==1.21.1
```


<br>


还不行的话，安装 `Visual C++ 2019` 可再发行组件包

使用搜索引擎排查错误，得知可能是 `DLL` 初始化失败可能与系统运行时库缺失有关，尝试安装 `Microsoft Visual C++ 2019 Redistributable：`

下载 `Visual C++ 2019 可再发行组件包`：{{< link href="https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" content="Visual C++ 2019 可再发行组件包" >}}



---
{.awesome-hr}


---

> 作者: [piliqiu](https://piliqiu.com/)  
> URL: https://piliqiu.com/posts/%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93dll%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BE%8B%E7%A8%8B%E5%A4%B1%E8%B4%A5/  

