TensorFlow的安装

1、官网介绍TensorFlow的安装,可以先了解一下。
https://www.tensorflow.org/versions/r0.12/get_started/os_setup#pip_installation
2、下面我们选择pip安装方法。
安装好以后导入tensorflow的模块
如果报下面的错误一:

[root@localhost ~]python
Python 2.7.13 (default, Jul  5 2017, 15:14:54)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/Python-2.7.13/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/opt/Python-2.7.13/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/opt/Python-2.7.13/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/opt/Python-2.7.13/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/opt/Python-2.7.13/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/opt/Python-2.7.13/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /opt/Python-2.7.13/lib/python2.7/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
[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版本需glibc2.14(升级到2.17),如下升级:

[root@localhost soft]# wget http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.gz
[root@localhost soft]# tar xf glibc-2.17.tar.gz
[root@localhost soft]# cd glibc-2.17
[root@localhost glibc-2.17]# mkdir build; cd build
[root@localhost build]# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

这里可能会报错,错误信息如下:

LD_LIBRARY_PATH shouldn't contain the current directory when building glibc. Please change the environment variable 

解决方法:
打印出你的echo $LD_LIBRARY_PATH的值,你会发现结尾会有一个“”:“”号,该值的解释这里引用其他人写的博客,我也是按照这个方法的去做的,我的操作是将$LD_LIBRARY_PATH值的末尾的冒号去掉了.
http://blog.csdn.net/ldl22847/article/details/18702645
http://blog.csdn.net/anda0109/article/details/39229597

接下来就是编译安装了,然后我们看看glibc升级到2.17这个版本了。

[root@localhost build]# make
[root@localhost build]# make install
[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_PRIVATE

import tensorflow 模块可能出现的错误二:

Python 2.7.13 (default, Jul 14 2017, 16:05:15)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/python/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/opt/python/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/opt/python/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/opt/python/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/opt/python/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.19' not found (required by /opt/python/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)
 
 
Failed to load the native TensorFlow runtime.
 
See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error
 

这里指出gcc的版本太低导致的,至于如何升级gcc的版本,之前写过一个gcc的文档。gcc的离线安装

运行以下命令检查动态库:

[root@localhost common]# strings /usr/lib64/libstdc++.so.6 | grep GLIBC
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
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.4
GLIBC_2.3.2
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

解决了这么多问题,当我们在引入这个模块的时候,还是有错,这可能是TensorFlow依赖其他的包,没办法继续pip install。
tensorflow依赖的python库安装:

pip install ipython numpy scipy pandas jupyter gensim scikit-learn polyglot

这里最好一个一个去安装。

感觉应该差不多了,导入该模块,发现尼玛又出错了,找了半天,原来是编码问题。
如果报 undefined symbol: PyUnicodeUCS4_AsASIIString 错误,是因为python和某个你用的库编译时指定的UCS编码不对导致,编译python时,可以通过指定–enable-unicode[=ucs[24]]来选择使用UCS2或者UCS4,如下:

解决方法:

[root@localhost Python-2.7.13]# ./configure --enable-shared --enable-unicode=ucs4
[root@localhost Python-2.7.13]# make
[root@localhost Python-2.7.13]# make install

这里相当于重新编译了python,可能会与之前安装的有所冲突,如果冲突了,重新修改环境变零或者创建软链接。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值