Failed to load the native TensorFlow runtime in Mac OS 10.11.6

當前環境:

  • Mac OSX 10.11.6
  • TensorFlow installed with pip
  • TensorFlow version: 1.13.0
  • Python version: 3.6.5

執行:import tensorflow as tf 時報如下錯誤:

Traceback (most recent call last):
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/Users/mikko/dev/wip/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/Users/mikko/dev/wip/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: dlopen(/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _clock_gettime
  Referenced from: /Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.so (which was built for Mac OS X 10.12)
  Expected in: /usr/lib/libSystem.B.dylib
 in /Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.so

During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/Users/mikko/dev/wip/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/Users/mikko/dev/wip/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: dlopen(/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _clock_gettime
  Referenced from: /Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.so (which was built for Mac OS X 10.12)
  Expected in: /usr/lib/libSystem.B.dylib
 in /Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.so


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

關鍵信息是:

ImportError: dlopen(/Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _clock_gettime
  Referenced from: /Users/mikko/dev/wip/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.so (which was built for Mac OS X 10.12)

libtensorflow_framework.so 編譯的目標版本爲 which was built for Mac OS X 10.12,而我當前的 Mac OS 版本是 10.11.6
https://github.com/tensorflow/tensorflow/issues/24642
中給出了 Mac OS Version < 10.12 版本的解決方案:

  • 安裝指定版本的 TensorFlow;
  • 使用 conda 安裝 TensorFlow;

本文采用方案一:
嘗試使用如下命令安裝:

python3 -m pip install tensorflow==1.5

拋出如下錯誤:

Collecting tensorflow==1.5
  Could not find a version that satisfies the requirement tensorflow==1.5 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 2.0.0a0)
No matching distribution found for tensorflow==1.5

解決方案:

python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.5.0-py3-none-any.whl

在這裏插入圖片描述
輸入 python3 進入命令行模式,然後輸入以下測試命令:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

輸出:
在這裏插入圖片描述
搞定!

參考:
https://github.com/tensorflow/tensorflow/issues/24642
https://www.tensorflow.org/install/pip
https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md
https://zhuanlan.zhihu.com/p/28362186
https://stackoverflow.com/questions/48720833/could-not-find-a-version-that-satisfies-the-requirement-tensorflow

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章