Traceback (most recent call last): File "D:\python-learn\dybgui\UI\LPR_GUI.py", line 756, in <module> window = Windows() File "D:\python-learn\dybgui\UI\LPR_GUI.py", line 243, in __init__ self.catcher = lpr3.LicensePlateCatcher() File "D:\python-learn\dybgui\.venv\lib\site-packages\hyperlpr3\hyperlpr3.py", line 22, in __init__ import onnxruntime as ort File "D:\python-learn\dybgui\.venv\lib\site-packages\onnxruntime\__init__.py", line 61, in <module> raise import_capi_exception File "D:\python-learn\dybgui\.venv\lib\site-packages\onnxruntime\__init__.py", line 24, in <module> from onnxruntime.capi._pybind_state import ( File "D:\python-learn\dybgui\.venv\lib\site-packages\onnxruntime\capi\_pybind_state.py", line 32, in <module> from .onnxruntime_pybind11_state import * # noqa ImportError: DLL load failed while importing onnxruntime_pybind11_state: 动态链接库(DLL)初始化例程失败。
时间: 2025-09-03 22:14:12 AIGC 浏览: 23
当Python导入onnxruntime时出现 “DLL load failed while importing onnxruntime_pybind11_state: 动态链接库(DLL)初始化例程失败” 的问题,可尝试以下解决办法:
1. **确认Python与onnxruntime版本兼容性**:确认Python是64位,并且安装的onnxruntime也是64位。可在终端输入以下命令进行查看:
```bash
python -c "import struct; print(struct.calcsize('P') * 8)"
```
若版本不兼容,需安装对应64位的版本 [^3]。
2. **更新ddddocr版本并修改代码**:若使用了ddddocr库,可将ddddocr版本升级到最新版,使用以下命令:
```bash
pip install -U ddddocr
```
通过`ctrl + 点击`进入到ddddocr的源代码界面,找到`__init__`文件(或者直接打开`.venv\Lib\site-packages\ddddocr\__init__.py`),搜索到如下代码:
```python
image = image.resize((int(image.size[0] * (64 / image.size[1])), 64), Image.ANTIALIAS).convert('L')
```
将其中的`Image.ANTIALIAS`修改为`Image.LANCZOS`,即:
```python
image = image.resize((int(image.size[0] * (64 / image.size[1])), 64), Image.LANCZOS).convert('L')
```
修改后运行代码,可能会出现一些彩色转义字符警告,但不影响使用 [^4]。
3. **降低onnxruntime版本**:若原来的onnxruntime版本太高,可尝试降低版本。例如原来是onnxruntime 1.19.0,可安装onnxruntime-gpu 1.14.1,使用以下命令:
```bash
pip install onnxruntime-gpu==1.14.1
```
需根据自身需求选择合适的版本,比如使用labelme需要onnxruntime大于等于1.14.1 [^5]。
阅读全文
相关推荐



















