linux系统安装Tensorflow

在线安装

直接pip install tensorflow
或者 conda install tensorflow

离线安装

最新版下载:
https://pypi.org/project/tensorflow/#files
历史版本下载:
https://pypi.org/project/tensorflow/#history

下载对应的安装包,本人选择 tensorflow-1.12.2-cp36-cp36m-manylinux1_x86_64.whl
进入安装包目录,pip install xxxxxx.whl
会提示依赖的文件不存在。接着百度去下载对应版本号的文件安装依赖包,有网的话会直接下载相关依赖库。
安装时出现下面提示:

  • distributed 1.21.8 requires msgpack, which is not installed.
    需要安装 msgpack库,下载离线包或直接pip install msgpack 安装。
  • You are using pip version 10.0.1, however version 19.1 is available.
    You should consider upgrading via the ‘pip install --upgrade pip’ command.
    按照提示更新pip

问题1:/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.17’ not found解决办法

之后, python中导入import tensorflow。出现下面错误:
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.17’ not found (required by /home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)
解决方法是:
在gcc官方下载gcc: http://ftp.gnu.org/gnu/gcc/ 高版本gcc。我下载了gcc-4.9.4 版。具体安装过程可参考:Linux 编译安装GNU gcc 4.9.4

安装完成后针对"GLIBCXX_3.4.17’ not found" , 需要手动拷贝libstdc++.so 文件到 /usr/lib64 并创建libstd++.so.6的软链接。

root@Master lib64]# cp /usr/local/lib64/libstdc++.so.6.0.20 /usr/lib64/
[root@Master lib64]# ln -sf libstdc++.so.6.0.20 libstdc++.so.6

问题2:/lib64/libc.so.6: version `GLIBC_2.16’ not found解决办法

再次 python中导入import tensorflow。出现下面错误:
ImportError: /lib64/libc.so.6: version `GLIBC_2.16’ not found (required by /home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)
解决方法是:
在gcc官方下载gcc: http://ftp.gnu.org/gnu/gcc/ 高版本。我下载了glibc-2.19.tar.gz版。具体安装过程可参考:Linux 编译安装GNU glibc
安装完成后仍有错误提示 , 需要手动拷贝libc-2.19.so 文件到 /lib64 并创建libc.so.6 指向新版本so文件的软链接。

问题3:FutureWarning: Conversion of … float to np.floating is deprecated 解决办法

再次 python中导入import tensorflow。出现下面警告:
FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated.

>>> import tensorflow
/home/dhy/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

需要更新h5py库,联网终端执行 pip install “h5py==2.8.0rc1” 。
可参考 https://blog.csdn.net/dhy012345/article/details/89393461

tensorflow具体安装过程

[root@Master PythonPacket]# pip install tensorflow-1.12.2-cp36-cp36m-manylinux1_x86_64.whl 
Processing ./tensorflow-1.12.2-cp36-cp36m-manylinux1_x86_64.whl
Requirement already satisfied: keras-preprocessing>=1.0.5 in /home/dhy/anaconda3/lib/python3.6/site-packages/Keras_Preprocessing-1.0.8-py3.6.egg (from tensorflow==1.12.2) (1.0.8)
Collecting gast>=0.2.0 (from tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/4e/35/11749bf99b2d4e3cceb4d55ca22590b0d7c2c62b9de38ac4a4a7f4687421/gast-0.2.2.tar.gz
Collecting grpcio>=1.8.6 (from tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/0a/9d/8bd5d0e516b196f59f1c4439b424b8d4fa62d492a4b531aae322d2d82a7b/grpcio-1.20.1-cp36-cp36m-manylinux1_x86_64.whl (2.1MB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 2.2MB 1.2MB/s 
Collecting absl-py>=0.1.6 (from tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/da/3f/9b0355080b81b15ba6a9ffcf1f5ea39e307a2778b2f2dc8694724e8abd5b/absl-py-0.7.1.tar.gz (99kB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 102kB 10.3MB/s 
Collecting tensorboard<1.13.0,>=1.12.0 (from tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/07/53/8d32ce9471c18f8d99028b7cef2e5b39ea8765bd7ef250ca05b490880971/tensorboard-1.12.2-py3-none-any.whl (3.0MB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 3.1MB 1.5MB/s 
Requirement already satisfied: wheel>=0.26 in /home/dhy/anaconda3/lib/python3.6/site-packages (from tensorflow==1.12.2) (0.31.1)
Requirement already satisfied: six>=1.10.0 in /home/dhy/anaconda3/lib/python3.6/site-packages (from tensorflow==1.12.2) (1.11.0)
Collecting termcolor>=1.1.0 (from tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Requirement already satisfied: keras-applications>=1.0.6 in /home/dhy/anaconda3/lib/python3.6/site-packages/Keras_Applications-1.0.7-py3.6.egg (from tensorflow==1.12.2) (1.0.7)
Requirement already satisfied: numpy>=1.13.3 in /home/dhy/anaconda3/lib/python3.6/site-packages (from tensorflow==1.12.2) (1.14.3)
Collecting protobuf>=3.6.1 (from tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/5a/aa/a858df367b464f5e9452e1c538aa47754d467023850c00b000287750fa77/protobuf-3.7.1-cp36-cp36m-manylinux1_x86_64.whl (1.2MB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1.2MB 1.8MB/s 
Collecting astor>=0.6.0 (from tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Requirement already satisfied: werkzeug>=0.11.10 in /home/dhy/anaconda3/lib/python3.6/site-packages (from tensorboard<1.13.0,>=1.12.0->tensorflow==1.12.2) (0.14.1)
Collecting markdown>=2.6.8 (from tensorboard<1.13.0,>=1.12.0->tensorflow==1.12.2)
  Downloading https://files.pythonhosted.org/packages/f5/e4/d8c18f2555add57ff21bf25af36d827145896a07607486cc79a2aea641af/Markdown-3.1-py2.py3-none-any.whl (87kB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 92kB 5.3MB/s 
Requirement already satisfied: h5py in /home/dhy/anaconda3/lib/python3.6/site-packages (from keras-applications>=1.0.6->tensorflow==1.12.2) (2.7.1)
Requirement already satisfied: setuptools in /home/dhy/anaconda3/lib/python3.6/site-packages (from protobuf>=3.6.1->tensorflow==1.12.2) (39.1.0)
Building wheels for collected packages: gast, absl-py, termcolor
  Running setup.py bdist_wheel for gast ... done
  Stored in directory: /root/.cache/pip/wheels/5c/2e/7e/a1d4d4fcebe6c381f378ce7743a3ced3699feb89bcfbdadadd
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: /root/.cache/pip/wheels/ee/98/38/46cbcc5a93cfea5492d19c38562691ddb23b940176c14f7b48
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: /root/.cache/pip/wheels/7c/06/54/bc84598ba1daf8f970247f550b175aaaee85f68b4b0c5ab2c6
Successfully built gast absl-py termcolor
distributed 1.21.8 requires msgpack, which is not installed.
Installing collected packages: gast, grpcio, absl-py, markdown, protobuf, tensorboard, termcolor, astor, tensorflow
Successfully installed absl-py-0.7.1 astor-0.7.1 gast-0.2.2 grpcio-1.20.1 markdown-3.1 protobuf-3.7.1 tensorboard-1.12.2 tensorflow-1.12.2 termcolor-1.1.0
You are using pip version 10.0.1, however version 19.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

安装msgpack

[root@Master PythonPacket]# pip install msgpack
Collecting msgpack
  Downloading https://files.pythonhosted.org/packages/92/7e/ae9e91c1bb8d846efafd1f353476e3fd7309778b582d2fb4cea4cc15b9a2/msgpack-0.6.1-cp36-cp36m-manylinux1_x86_64.whl (248kB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 256kB 924kB/s 
Installing collected packages: msgpack
Successfully installed msgpack-0.6.1
You are using pip version 10.0.1, however version 19.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

更新pip

[root@Master PythonPacket]# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/f9/fb/863012b13912709c13cf5cfdbfb304fa6c727659d6290438e1a88df9d848/pip-19.1-py2.py3-none-any.whl (1.4MB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1.4MB 576kB/s 
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-19.1

测试tensorflow安装:
报错情况:

[root@Master PythonPacket]# python 
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "/home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/dhy/anaconda3/lib/python3.6/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 "/home/dhy/anaconda3/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/home/dhy/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.17' not found (required by /home/dhy/anaconda3/lib/python3.6/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 "/home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/dhy/anaconda3/lib/python3.6/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 "/home/dhy/anaconda3/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/home/dhy/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.17' not found (required by /home/dhy/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

安装成功

[root@Master build]# python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值