导入 onnxruntime 时出现错误 ImportError:无法导入名称“get_all_providers”(Windows 10)

问题描述 投票:0回答:3

我已经在我的环境中安装了 onnxruntime-gpu 库

pip install onnxruntime-gpu==1.2.0

nvcc --version output
Cuda compilation tools, release 10.1, V10.1.105

>>> import onnxruntime
C:\Users\abgangwa\AppData\Local\Continuum\anaconda3\envs\onnx_gpu\lib\site-packages\onnxruntime\capi\_pybind_state.py:13: UserWarning: Cannot load onnxruntime.capi. Error: 'DLL load failed: The specified module could not be found.'
  warnings.warn("Cannot load onnxruntime.capi. Error: '{0}'".format(str(e)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\abgangwa\AppData\Local\Continuum\anaconda3\envs\onnx_gpu\lib\site-packages\onnxruntime\__init__.py", line 12, in <module>
    from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, RunOptions, SessionOptions, set_default_logger_severity, NodeArg, ModelMetadata, GraphOptimizationLevel, ExecutionMode
ImportError: cannot import name 'get_all_providers'

请帮我解决这个错误

尝试了现有的解决方案。他们都不起作用

importerror onnx onnxruntime
3个回答
2
投票

只需安装合适的版本:

pip install onnxruntime
#仅适用于CPU

pip install onnxruntime-gpu
#GPU


0
投票

很可能 CUDA dll 不在路径中,因此当 python 加载 onnxruntime 库时找不到。

此回复包含有关解决此问题的文章的链接。

https://github.com/microsoft/onnxruntime/issues/4196#issuecomment-808787338


0
投票

我尝试了该命令,但我得到:

pip install onnxruntime-gpu
WARNING: Ignoring invalid distribution -ip (c:\users\damie\appdata\local\programs\python\python310\lib\site-packages)
Requirement already satisfied: onnxruntime-gpu in c:\users\damie\appdata\local\programs\python\python310\lib\site-packages (1.16.2)
Requirement already satisfied: coloredlogs in c:\users\damie\appdata\local\programs\python\python310\lib\site-packages (from onnxruntime-gpu) (15.0.1)
Requirement already satisfied: flatbuffers in c:\users\damie\appdata\local\programs\python\python310\lib\site-packages (from onnxruntime-gpu) (23.5.26)
Requirement already satisfied: numpy>=1.21.6 in c:\users\damie\appdata\roaming\python\python310\site-packages (from onnxruntime-gpu) (1.26.2)
Requirement already satisfied: packaging in c:\users\damie\appdata\roaming\python\python310\site-packages (from onnxruntime-gpu) (23.2)
Requirement already satisfied: protobuf in c:\users\damie\appdata\roaming\python\python310\site-packages (from onnxruntime-gpu) (4.25.1)
Requirement already satisfied: sympy in c:\users\damie\appdata\local\programs\python\python310\lib\site-packages (from onnxruntime-gpu) (1.12)
Requirement already satisfied: humanfriendly>=9.1 in c:\users\damie\appdata\local\programs\python\python310\lib\site-packages (from coloredlogs->onnxruntime-gpu) (10.0)
Requirement already satisfied: mpmath>=0.19 in c:\users\damie\appdata\local\programs\python\python310\lib\site-packages (from sympy->onnxruntime-gpu) (1.3.0)
Requirement already satisfied: pyreadline3 in c:\users\damie\appdata\local\programs\python\python310\lib\site-packages (from humanfriendly>=9.1->coloredlogs->onnxruntime-gpu) (3.4.1)
WARNING: Ignoring invalid distribution -ip (c:\users\damie\appdata\local\programs\python\python310\lib\site-packages)
© www.soinside.com 2019 - 2024. All rights reserved.