centos6.x 安裝tensorflow異常處理

frank12-12發表於2018-04-23

利用pip安裝TensorFlow,執行命令pip install tensorflow,但是安裝過程顯示成功,但是不能使用,通常遇到GLIBCGLIBCXX異常資訊:

異常如下:

>>>import tensorflow as tf

Traceback(most recent call last):

  File"/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py",line 41, in <module>

    fromtensorflow.python.pywrap_tensorflow_internal import *

  File"/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py",line 28, in <module>

    _pywrap_tensorflow_internal =swig_import_helper()

  File"/usr/local/python3.5/lib/python3.5/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"/usr/local/python3.5/lib/python3.5/imp.py", line 242, in load_module

    return load_dynamic(name, filename, file)

  File"/usr/local/python3.5/lib/python3.5/imp.py", line 342, inload_dynamic

    return _load(spec)

ImportError:/lib64/libc.so.6: version `GLIBC_2.14' not found (required by/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

 

Duringhandling of the above exception, another exception occurred:

 

Traceback(most recent call last):

  File "<stdin>", line 1, in<module>

  File"/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/__init__.py",line 24, in <module>

    from tensorflow.python import *

  File"/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/__init__.py",line 49, in <module>

    from tensorflow.python importpywrap_tensorflow

  File"/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py",line 52, in <module>

    raise ImportError(msg)

ImportError:Traceback (most recent call last):

  File"/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py",line 41, in <module>

    from tensorflow.python.pywrap_tensorflow_internalimport *

  File"/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py",line 28, in <module>

    _pywrap_tensorflow_internal =swig_import_helper()

  File"/usr/local/python3.5/lib/python3.5/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"/usr/local/python3.5/lib/python3.5/imp.py", line 242, in load_module

    return load_dynamic(name, filename, file)

  File"/usr/local/python3.5/lib/python3.5/imp.py", line 342, inload_dynamic

    return _load(spec)

ImportError:/lib64/libc.so.6: version `GLIBC_2.14' not found (required by/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

 

 

Failedto load the native TensorFlow runtime.

 

Seehttps://www.tensorflow.org/install/install_sources#common_installation_problems

 

forsome common reasons and solutions. Include the entire stack trace

abovethis error message when asking for help.


原因GLIBC_2.14 版本太低:

GLIBC版本檢視

[root@localhost ~]# strings/lib64/libc.so.6|grep GLIBC

GLIBC_2.2.5

GLIBC_2.2.6

GLIBC_2.3

GLIBC_2.3.2

GLIBC_2.3.3

GLIBC_2.3.4

GLIBC_2.4

GLIBC_2.5

GLIBC_2.6

GLIBC_2.7

GLIBC_2.8

GLIBC_2.9

GLIBC_2.10

GLIBC_2.11

GLIBC_2.12

GLIBC_PRIVATE

解決辦法

GLIBC版本升級:

步驟如下:

wget http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz

tar -xvf glibc-2.18.tar.gz

cd glibc-2.18

mkdir build && cd build

../configure --prefix=/usr--disable-profile --enable-add-ons --with-headers=/usr/include--with-binutils=/usr/bin 

make&& make install

安裝完成後檢視GLIBC版本:

[root@localhost build]# strings/lib64/libc.so.6|grep GLIBC

GLIBC_2.2.5

GLIBC_2.2.6

GLIBC_2.3

GLIBC_2.3.2

GLIBC_2.3.3

GLIBC_2.3.4

GLIBC_2.4

GLIBC_2.5

GLIBC_2.6

GLIBC_2.7

GLIBC_2.8

GLIBC_2.9

GLIBC_2.10

GLIBC_2.11

GLIBC_2.12

GLIBC_2.13

GLIBC_2.14

GLIBC_2.15

GLIBC_2.16

GLIBC_2.17

GLIBC_2.18

GLIBC_PRIVATE

 

GLIBCXX版本異常

異常資訊

>>> import tensorflow as tf

Traceback (most recent call last):

  File "/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>

    from tensorflow.python.pywrap_tensorflow_internal import *

  File "/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>

    _pywrap_tensorflow_internal = swig_import_helper()

  File "/usr/local/python3.5/lib/python3.5/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 "/usr/local/python3.5/lib/python3.5/imp.py", line 242, in load_module

    return load_dynamic(name, filename, file)

  File "/usr/local/python3.5/lib/python3.5/imp.py", line 342, in load_dynamic

    return _load(spec)

ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by /usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>

    from tensorflow.python import *

  File "/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 49, in <module>

    from tensorflow.python import pywrap_tensorflow

  File "/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>

    raise ImportError(msg)

ImportError: Traceback (most recent call last):

  File "/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>

    from tensorflow.python.pywrap_tensorflow_internal import *

  File "/usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>

    _pywrap_tensorflow_internal = swig_import_helper()

  File "/usr/local/python3.5/lib/python3.5/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 "/usr/local/python3.5/lib/python3.5/imp.py", line 242, in load_module

    return load_dynamic(name, filename, file)

  File "/usr/local/python3.5/lib/python3.5/imp.py", line 342, in load_dynamic

    return _load(spec)

ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by /usr/local/python3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

 

 

Failed to load the native TensorFlow runtime.

 

See https://www.tensorflow.org/install/install_sources#common_installation_problems

 

for some common reasons and solutions.  Include the entire stack trace




GLIBCXX版本檢視

[root@redhat ~]# strings/usr/lib64/libstdc++.so.6 | grep GLIBCXX

GLIBCXX_3.4

GLIBCXX_3.4.1

GLIBCXX_3.4.2

GLIBCXX_3.4.3

GLIBCXX_3.4.4

GLIBCXX_3.4.5

GLIBCXX_3.4.6

GLIBCXX_3.4.7

GLIBCXX_3.4.8

GLIBCXX_3.4.9

GLIBCXX_3.4.10

GLIBCXX_3.4.11

GLIBCXX_3.4.12

GLIBCXX_3.4.13

GLIBCXX_FORCE_NEW

GLIBCXX_DEBUG_MESSAGE_LENGTH

 

解決辦法

GLIBCXX升級

wget http://ftp.de.debian.org/debian/pool/main/g/gcc-4.9/libstdc++6_4.9.2-10_amd64.deb

[root@localhost]# tar -x libstdc++6_4.9.2-10_amd64.deb && tar xvfdata.tar.xz

[root@localhost]# mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak

[root@localhost]#cp usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20 /usr/lib64/

[root@localhost]# chmod +x /usr/lib64/libstdc++.so.6.0.20

[root@localhost]# ln -s /usr/lib64/libstdc++.so.6.0.20 /usr/lib64/libstdc++.so.6

[root@localhost]# strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

GLIBCXX_3.4

GLIBCXX_3.4.1

GLIBCXX_3.4.2

GLIBCXX_3.4.3

GLIBCXX_3.4.4

GLIBCXX_3.4.5

GLIBCXX_3.4.6

GLIBCXX_3.4.7

GLIBCXX_3.4.8

GLIBCXX_3.4.9

GLIBCXX_3.4.10

GLIBCXX_3.4.11

GLIBCXX_3.4.12

GLIBCXX_3.4.13

GLIBCXX_3.4.14

GLIBCXX_3.4.15

GLIBCXX_3.4.16

GLIBCXX_3.4.17

GLIBCXX_3.4.18

GLIBCXX_3.4.19

GLIBCXX_3.4.20

\GLIBCXX_DEBUG_MESSAGE_LENGTH

測試:

>>>import tensorflow as tf

>>> 

無異常丟擲,說明安裝TensorFlow可以使用了