无法加载本机TensorFlow运行时:导入tensorflow时出错

时间:2017-05-19 07:46:34

标签: python tensorflow

我在Ubuntu 17.04 32bit上从源代码构建了TensorFlow

导入tensorflow时收到此消息

palash @ ash:〜$ python

Python 3.6.0 |Anaconda 4.3.1 (32-bit)| (default, Dec 23 2016, 12:22:10) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/home/palash/anaconda3/lib/python3.6/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/palash/anaconda3/lib/python3.6/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/palash/anaconda3/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow.so)

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/home/palash/anaconda3/lib/python3.6/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/palash/anaconda3/lib/python3.6/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/palash/anaconda3/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/palash/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow.so)

无法加载本机TensorFlow运行时。

请参阅https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

出于一些常见原因和解决方案。包括整个堆栈跟踪 请求帮助时出现此错误消息。

my bazel info:
palash@ash:~$ bazel version
Build label: 0.4.5- (@non-git)
Build target: bazel-out/local-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri May 19 01:31:26 2017 (1495157486)
Build timestamp: 1495157486
Build timestamp as int: 1495157486

my TensorFlow version : 1.0.1

2 个答案:

答案 0 :(得分:2)

我在某种程度上找到了解决方案,也许在tensorflow 1.6或更高版本中似乎存在一些兼容性错误。

将tensorflow降级到1.5版解决了我的问题。

为此,我建议使用pip uninstall tensorflow卸载tensorflow 1.8版,然后再次使用pip install tensorflow==1.5安装1.5版。

此外,我建议您也卸载并重新安装keras库。

答案 1 :(得分:0)

可能是由于兼容性问题。对于我的Ubuntu 18服务器,我必须使用tensorflow == 1.12,并且现在可以使用。

尝试从最新版本(1.12,现在为2019年3月26日)降级,并查看哪个版本有效。

此脚本尝试版本(trytfver.sh):

pip uninstall tensorflow -y
pip install --user tensorflow==$1
python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

尝试如下操作:

bash trytfver.sh 1.12
bash trytfver.sh 1.11
bash trytfver.sh 1.10
bash trytfver.sh 1.9
bash trytfver.sh 1.8
bash trytfver.sh ...

并查看是否出现任何“未定义符号”错误,例如,我在1.11上有错误。