Skip to content

onnxruntime by macOS

daigomiyoshi edited this page Nov 3, 2020 · 1 revision

mac OSでonnxruntimeをimportする際に、以下のようねエラーが生じた。

実行コード

pip install onnxruntime

import onnxruntime

エラー

/Users/.../lib/python3.7/site-packages/onnxruntime/capi/_pybind_state.py:14: UserWarning: Cannot load onnxruntime.capi. Error: 'dlopen(/Users/.../lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.so, 2): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
  Referenced from: /Users/.../lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.so
  Reason: image not found'.
  warnings.warn("Cannot load onnxruntime.capi. Error: '{0}'.".format(str(e)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../lib/python3.7/site-packages/onnxruntime/__init__.py", line 13, in <module>
    from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, set_seed, \
ImportError: cannot import name 'get_all_providers' from 'onnxruntime.capi._pybind_state' (/Users/.../lib/python3.7/site-packages/onnxruntime/capi/_pybind_state.py)

OS versionによって異なるかもしれないが、当該リンク通りに、

brew install libomp

のインストールにより、実行成功

Clone this wiki locally