web123456

Use pip to install tensorflow 0.80, Python uses tensorflow 0.80 and the problem and how to deal with it

The business needs to use Google's deep learning framework tensorflow. We encountered many problems during the installation process, which is really difficult to deal with. We will record it here.


CentOS6.4
tensorflow 0.80

Python-2.7.11


1. Uninstall the original pip
2. Download a pip website/en/latest/installing/
3、yum install python-devel libffi-devel openssl-devel

#python

Report an error:
: can't decompress data; zlib not available error
The solution is to recompile the Python source code installation package, as follows:
tar zxvf Python-2.7.
cd Python-2.7.11
./configure
vi Modules/Setup
Here, find the 454 lines
#zlib -I$(prefix)/include -L$(exec_prefix)/lib -lz
Remove comments
zlib -I$(prefix)/include -L$(exec_prefix)/lib -lz
make
make install


Error: ImportError: cannot import name HTTPSHandler
solve:
yum install -y openssl openssl-devel
Then recompile python

Install tensorflow
pip install --upgrade /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 import *
  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>
    from 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/.6: version `GLIBC_2.15' not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)


When the tensorflow0.80 version is compiled, GLIBC_2.15 is used, and the system comes with GLIBC_2.12, so an error is reported.

Install the new version of glibc

download
Download the source code from /software/libc/. The version I downloaded is 2.20 and the link address is /gnu/glibc/glibc-2.

2. Installation
Because the glibc library is widely used, in order to avoid polluting the current system environment, it is best to customize the installation directory and define the environment variables when using it. The specific steps are as follows:

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

Use this method online (not modifying the original system environment glibc, create a new directory to install and call the new version of glibc),But I didn't succeed, don't use this method, refer to the installation method later.Because $LD_LIBRARY_PATH has no default content
# tar xvf glibc-2.
# 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. Test
[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
-----------------------------------------------------------------------------------------------------

Serious problems deal with:
During the installation process, after modifying the /etc/ file and ldconfig, an error was reported after entering the command:
#ls
ls: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument

Commands that can be used:
echo "include /*.conf" > /etc/

Temporary solution to the method that can use ls, mv, cp, cat and other commands:
export LD_LIBRARY_PATH=/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH
Modify /etc/ to the original content
Execute ldconfig to restore normal

(The purpose of the ldconfig command is mainly in the default search directory (/lib and /usr/lib) and the directories listed in the dynamic library configuration file /etc/.
Search for shared dynamic link libraries (format as described above, lib*.so*), and then create connection and cache files required for dynamic loader().

The cache file defaults to /etc/, which saves a list of dynamic link library names that have been sorted.)


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

Many commands are not easy to use
Never disconnect ssh, otherwise you won't be able to go up remotely
vi /etc/profile Join
export LD_LIBRARY_PATH=/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib:/usr/local/lib64

# echo $LD_LIBRARY_PATH
Continue to reinstall glibc-2.17 (refer to the installation below)

-----------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------


The method I'm using (upgrade glibc directly):

yum install gcc

wget /pub/gnu/glibc/glibc-2.
xz -d glibc-2.
tar -xvf glibc-2.
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
It takes about 10 minutes to wait.

Enter strings /lib64/.6|grep GLIBC found that it has been updated
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 import *
  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>
    from 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

There is no support for GLIBCXX_3.4.14, continue to install(Note: libstdc++6_4.7.2-5_amd64.deb is 64 bit, libstdc++6_4.7.2-5_i386.deb is 32 bit)

Download the new version, address: /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  

#cd /root/usr/lib/x86_64-linux-gnu (enter the directory where the decompressed file is, I am decompressed in the /root directory)
#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.
#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 import *
  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>
    from 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)



Download libstdc++.so.6.0.20 from the Internet

/debian/pool/main/g/gcc-4.8/
or
/detail/pomelover/7524227


Put it in /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



Finally succeeded.
[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 = ([[3., 3.]])
>>> matrix2 = ([[2.],[2.]])
>>> product = (matrix1, matrix2)
>>> print product
Tensor("MatMul:0", shape=(1, 1), dtype=float32)
>>> sess = ()
>>> result = (product)
>>> print result
[[ 12.]]
>>> ()
>>> exit()


Record the above content to help friends in need.

refer to:
/questions/7446187/no-module-named-pkg-resources
/
/zhangxu0512/blog/262275
/bboxhe/article/details/46849167
/questions/33655731/error-while-importing-tensorflow-in-python2-7-in-ubuntu-12-04-glibc-2-17-not-f
/officercat/article/details/39520227
/
/lib0129/article/details/23345791
/testcs_dn/article/details/45456815
/abcd1f2/article/details/49777715