使用pip安装tensorflow 0.80,python 使用tensorflow 0.80遇到的问题及处理方法

  • Post author:
  • Post category:python


业务需要使用谷歌的深度学习框架tensorflow,安装过程中遇到很多问题,真的很难处理,特此记录。

CentOS6.4

tensorflow 0.80

Python-2.7.11

1、卸载原来的pip

2、下载个pip 网站https://pip.pypa.io/en/latest/installing/

3、yum install python-devel libffi-devel openssl-devel

#python get-pip.py

报错:

出现:zipimport.ZipImportError: can’t decompress data; zlib not available错误

解决办法重新编译一下Python源码安装包,如下:

tar zxvf Python-2.7.11.tgz

cd Python-2.7.11

./configure

vi Modules/Setup

在这里把454行左右的 找到

#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

去掉注释

zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

make

make install

报错:ImportError:cannot import name HTTPSHandler

解决:

yum install -y openssl openssl-devel

然后重新编译python

安装tensorflow

pip install –upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

Python 2.7.3 (default, Apr 26 2016, 11:18:30)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] 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 “/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py”, line 23, in <module>

from tensorflow.python import *

File “/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py”, line 45, in <module>

from tensorflow.python import pywrap_tensorflow

File “/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 28, in <module>

_pywrap_tensorflow = swig_import_helper()

File “/usr/local/python27/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: /lib64/libc.so.6: version `GLIBC_2.15′ not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

tensorflow0.80版本编译的时候使用GLIBC_2.15,系统自带的是GLIBC_2.12,所以报错了。

安装新版glibc

1.glibc下载

从http://www.gnu.org/software/libc/ 下载源代码。我下载的版本是2.20,链接地址是http://ftp.gnu.org/gnu/glibc/glibc-2.20.tar.gz

2.安装

因为glibc库使用广泛,为了避免污染当前系统环境,最好自定义安装目录,使用时定义一下环境变量就行了。具体步骤如下:

————————————————————————————————

————————————————————————————————

网上使用这个方法(不修改原系统环境glibc,新建个目录安装调用新版glibc),


但是我没有成功,不要使用这个方法,参考后边的安装方法,


因为$LD_LIBRARY_PATH没有默认的内容

# tar xvf glibc-2.20.tar.gz

# cd glibc-2.20

[root@localhost glibc-2.20]# mkdir build

[root@localhost glibc-2.20]# cd ./build

[root@localhost build]# ../configure –prefix=/opt/glibc-2.20

[root@localhost build]# make -j4

[root@localhost build]# make install

3.测试

[root@localhost nvEncodeApp]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:/opt/glibc-2.20/lib

[root@localhost nvEncodeApp]# ./nvEncoder

export LD_LIBRARY_PATH=/usr/local/lib:/opt/glibc-2.20/lib:$LD_LIBRARY_PATH

—————————————————————————————————–



严重问题处理:



安装过程中,因为修改/etc/ld.so.conf文件,ldconfig后导致输入命令后,报错:

#ls

ls: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument

可以使用的命令:

echo “include ld.so.conf.d/*.conf” > /etc/ld.so.conf

临时解决可以使用ls、mv、cp、cat等命令的方法:

export LD_LIBRARY_PATH=/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH

修改/etc/ld.so.conf为原来的内容

执行ldconfig,恢复正常

(ldconfig 命令的用途,主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下,

搜索出可共享的动态链接库(格式如前介绍,lib*.so*),进而创建出动态装入程序(ld.so)所需的连接和缓存文件.

缓存文件默认为/etc/ld.so.cache,此文件保存已排好序的动态链接库名字列表.)

configure: error:

LD_LIBRARY_PATH shouldn’t contain the current directory when building glibc. Please change the environment variable and run configure again.

很多命令不好用了

千万不要断开ssh,不然就远程不上去了

vi /etc/profile 加入

export LD_LIBRARY_PATH=/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib:/usr/local/lib64

# echo $LD_LIBRARY_PATH

继续重新安装glibc-2.17(参考下边的安装)

———————————————————————————————————–

————————————————————————————————



我使用的方法(直接升级glibc):

yum install gcc

wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.17.tar.xz

xz -d glibc-2.17.tar.xz

tar -xvf glibc-2.17.tar

cd glibc-2.17

mkdir build

cd build

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

make && make install

需要等大概10分钟。

输入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

Python 2.7.3 (default, Apr 26 2016, 11:18:30)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] 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 “/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py”, line 23, in <module>

from tensorflow.python import *

File “/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py”, line 45, in <module>

from tensorflow.python import pywrap_tensorflow

File “/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 28, in <module>

_pywrap_tensorflow = swig_import_helper()

File “/usr/local/python27/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.14′ not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)


ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14′ not found

#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_3.4.14版本支持,继续安装


(注意:libstdc++6_4.7.2-5_amd64.deb这是64位,libstdc++6_4.7.2-5_i386.deb这个是32位)

下载新版本,地址:http://ftp.de.debian.org/debian/pool/main/g/gcc-4.7/libstdc++6_4.7.2-5_amd64.deb

ar -x libstdc++6_4.7.2-5_amd64.deb&&tar xvf data.tar.gz

#cd /root/usr/lib/x86_64-linux-gnu (进入解压文件的目录中,我这里是下/root目录下解压的)

#ll

lrwxrwxrwx 1 root root     19 Apr 26 15:21 libstdc++.so.6 -> libstdc++.so.6.0.17

-rw-r–r– 1 root root 991600 Jan  7  2013 libstdc++.so.6.0.17

# find / -name libstdc++.so.6

/usr/lib64/libstdc++.so.6

/root/usr/lib/x86_64-linux-gnu/libstdc++.so.6

#mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak

#cp libstdc++.so.6.0.17 /usr/lib64/

#cd /usr/lib64/

#chmod +x libstdc++.so.6.0.17

#ll libstdc++.so.6.0.17

-rwxr-xr-x 1 root root 991600 Apr 26 15:30 libstdc++.so.6.0.17

#ln -s libstdc++.so.6.0.17 libstdc++.so.6

#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_DEBUG_MESSAGE_LENGTH

>>> import tensorflow as tf

Traceback (most recent call last):

File “<stdin>”, line 1, in <module>

File “/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py”, line 23, in <module>

from tensorflow.python import *

File “/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py”, line 45, in <module>

from tensorflow.python import pywrap_tensorflow

File “/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 28, in <module>

_pywrap_tensorflow = swig_import_helper()

File “/usr/local/python27/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 /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

从网上下载libstdc++.so.6.0.20

http://ftp.de.debian.org/debian/pool/main/g/gcc-4.8/

或者

http://download.csdn.net/detail/pomelover/7524227

放到/usr/lib64/下

#chmod +x libstdc++.so.6.0.20

#rm libstdc++.so.6

#ln -s libstdc++.so.6.0.20 libstdc++.so.6

#strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

[root@pachong1 lib64]# 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_FORCE_NEW

GLIBCXX_DEBUG_MESSAGE_LENGTH

终于成功了。

[root@pachong1 lib64]# python

Python 2.7.3 (default, Apr 26 2016, 11:18:30)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

>>> import tensorflow as tf

>>> matrix1 = tf.constant([[3., 3.]])

>>> matrix2 = tf.constant([[2.],[2.]])

>>> product = tf.matmul(matrix1, matrix2)

>>> print product

Tensor(“MatMul:0”, shape=(1, 1), dtype=float32)

>>> sess = tf.Session()

>>> result = sess.run(product)

>>> print result

[[ 12.]]

>>> sess.close()

>>> exit()

以上内容记录下,帮助需要的朋友。

参考:

http://stackoverflow.com/questions/7446187/no-module-named-pkg-resources

http://blog.chinaunix.net/uid-25691489-id-5577387.html

http://my.oschina.net/zhangxu0512/blog/262275

http://blog.csdn.net/bboxhe/article/details/46849167

http://stackoverflow.com/questions/33655731/error-while-importing-tensorflow-in-python2-7-in-ubuntu-12-04-glibc-2-17-not-f

http://blog.csdn.net/officercat/article/details/39520227

http://blog.chinaunix.net/uid-354915-id-3568853.html

http://blog.csdn.net/lib0129/article/details/23345791

http://blog.csdn.net/testcs_dn/article/details/45456815

http://blog.csdn.net/abcd1f2/article/details/49777715



版权声明:本文为levy_cui原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。