TensorFlow工作笔记001---Centos7.3下安装TensorFlow最新版本,基于python2.7.5的,没有编译TensorFlow的源码

版权声明:本文为博主原创文章,未经博主credreamer 允许不得转载 违者追究法律责任。 https://blog.csdn.net/lidew521/article/details/88138268

技术交流QQ群【JAVA,.NET,BigData,AI】:170933152  

Centos7.3下安装TensorFlow最新版本,基于python2.7.5的,没有编译TensorFlow的源码,这样不好啊,没有编译源码,没有

经过,优化,TensorFlow跑起来挺慢,而且会有一些警告。但是这样安装快。先装上再说吧。

 人工智能第一步啊:

前奏:如果想装高版本的python,可以这样

[root@localhost opt]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
--2019-03-05 03:52:35--  https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
Resolving www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:36::223
Connecting to www.python.org (www.python.org)|151.101.228.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22897802 (22M) [application/octet-stream]
Saving to: ‘Python-3.7.2.tgz’

 1% [>                                                                                                                                         ] 316,984     29.7KB/s  eta 12m 13s
 1% [=>                                                                                                                                        ] 333,283     29.0KB/s  eta 12m 13s
 1% [=>                                                                                                                                        ] 346,993     31.0KB/s  eta 12m 22s
 1% [=>                                                                                                                                        ] 357,859     30.7KB/s  eta 12m 22s


 1% [=>                                                                                                                                        ] 371,654     30.5KB/s  eta 12m 22s
100%[=========================================================================================================================================>] 22,897,802  27.1KB/s   in 11m 58s

2019-03-05 04:04:36 (31.2 KB/s) - ‘Python-3.7.2.tgz’ saved [22897802/22897802]

1.首先检查CentOS有没有安装python-pip包,直接执行:yum install python-pip。 

[root@localhost opt]# yum install python-pip
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.tuna.tsinghua.edu.cn
base                                                                                                                                                        | 3.6 kB  00:00:00     
extras                                                                                                                                                      | 3.4 kB  00:00:00     
updates                                                                                                                                                     | 3.4 kB  00:00:00     
base/7/x86_64/primary_db       FAILED                                          [                                                                 ]  0.0 B/s |    0 B  --:--:-- ETA 
http://mirrors.cqu.edu.cn/CentOS/7.6.1810/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
Trying other mirror.
(1/4): extras/7/x86_64/primary_db                                                                                                                           | 180 kB  00:00:00     
(2/4): base/7/x86_64/group_gz                                                                                                                               | 166 kB  00:00:00     
(3/4): updates/7/x86_64/primary_db                                                                                                                          | 2.4 MB  00:00:00     
base/7/x86_64/primary_db       FAILED                                          [===============================-                                 ]   21 B/s | 4.3 MB  62:16:40 ETA 
http://mirrors.neusoft.edu.cn/centos/7.6.1810/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.neusoft.edu.cn/centos/7.6.1810/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
base/7/x86_64/primary_db       FAILED                                          [================================                                 ]   79 B/s | 4.3 MB  16:25:29 ETA 
http://ap.stykers.moe/centos/7.6.1810/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 12] Timeout on http://ap.stykers.moe/centos/7.6.1810/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(4/4): base/7/x86_64/primary_db                                                                                                                             | 6.0 MB  00:01:53     
No package python-pip available.
Error: Nothing to do


2.如提示没有python-pip包,可对yum的软件仓库提供额外的软件包,执行命令: yum -y install epel-release。 

[root@localhost opt]# yum -y install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================
 Package                                         Arch                                      Version                                 Repository                                 Size
===================================================================================================================================================================================
Installing:
 epel-release                                    noarch                                    7-11                                    extras                                     15 k

Transaction Summary
===================================================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm                                                                                                                                |  15 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : epel-release-7-11.noarch                                                                                                                                        1/1 
  Verifying  : epel-release-7-11.noarch                                                                                                                                        1/1 

Installed:
  epel-release.noarch 0:7-11                                                                                                                                                       

Complete!


3.执行成功之后,再次执行:yum install python-pip。 

[root@localhost opt]# yum install python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                        | 7.4 kB  00:00:00     
 * base: mirrors.163.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.tuna.tsinghua.edu.cn
epel                                                                                                                                                        | 4.7 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                                                                                                                 |  88 kB  00:00:00     
(2/3): epel/x86_64/updateinfo                                                                                                                               | 960 kB  00:00:00     
(3/3): epel/x86_64/primary_db                                                                                                                               | 6.6 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package python2-pip.noarch 0:8.1.2-7.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================
 Package                                       Arch                                     Version                                       Repository                              Size
===================================================================================================================================================================================
Installing:
 python2-pip                                   noarch                                   8.1.2-7.el7                                   epel                                   1.7 M

Transaction Summary
===================================================================================================================================================================================
Install  1 Package

Total download size: 1.7 M
Installed size: 7.2 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/python2-pip-8.1.2-7.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for python2-pip-8.1.2-7.el7.noarch.rpm is not installed
python2-pip-8.1.2-7.el7.noarch.rpm                                                                                                                          | 1.7 MB  00:00:00     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <[email protected]>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python2-pip-8.1.2-7.el7.noarch                                                                                                                                  1/1 
  Verifying  : python2-pip-8.1.2-7.el7.noarch                                                                                                                                  1/1 

Installed:
  python2-pip.noarch 0:8.1.2-7.el7                                                                                                                                                 

Complete!


4.此时安装好的pip版本为0.8,非最新版本,可对其进行升级 pip install –upgrade pip。 

[root@localhost opt]# pip install -upgrade pip

Usage:   
  pip install [options] <requirement specifier> [package-index-options] ...
  pip install [options] -r <requirements file> [package-index-options] ...
  pip install [options] [-e] <vcs project url> ...
  pip install [options] [-e] <local project path> ...
  pip install [options] <archive url/path> ...

no such option: -u
[root@localhost opt]# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 29kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
      Successfully uninstalled pip-8.1.2
Successfully installed pip-19.0.3

5.升级成功之后,便可以通过pip快速地安装TensorFlow:pip install tensorflow。 

[root@localhost opt]# pip install tensorflow
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting tensorflow
  Downloading https://files.pythonhosted.org/packages/d2/ea/ab2c8c0e81bd051cc1180b104c75a865ab0fc66c89be992c4b20bbf6d624/tensorflow-1.13.1-cp27-cp27mu-manylinux1_x86_64.whl (92.5MB)
    100% |████████████████████████████████| 92.5MB 10kB/s 
Collecting keras-preprocessing>=1.0.5 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/c0/bf/0315ef6a9fd3fc2346e85b0ff1f5f83ca17073f2c31ac719ab2e4da0d4a3/Keras_Preprocessing-1.0.9-py2.py3-none-any.whl (59kB)
    100% |████████████████████████████████| 61kB 26.2MB/s 
Collecting enum34>=1.1.6 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl
Collecting astor>=0.6.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Collecting backports.weakref>=1.0rc1 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/88/ec/f598b633c3d5ffe267aaada57d961c94fdfa183c5c3ebda2b6d151943db6/backports.weakref-1.0.post1-py2.py3-none-any.whl
Collecting wheel (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/96/ba/a4702cbb6a3a485239fbe9525443446203f00771af9ac000fa3ef2788201/wheel-0.33.1-py2.py3-none-any.whl
Collecting mock>=2.0.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/e6/35/f187bdf23be87092bd0f1200d43d23076cee4d0dec109f195173fd3ebc79/mock-2.0.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 18.8MB/s 
Collecting tensorflow-estimator<1.14.0rc0,>=1.13.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/bb/48/13f49fc3fa0fdf916aa1419013bb8f2ad09674c275b4046d5ee669a46873/tensorflow_estimator-1.13.0-py2.py3-none-any.whl (367kB)
    100% |████████████████████████████████| 368kB 63kB/s 
Collecting gast>=0.2.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/4e/35/11749bf99b2d4e3cceb4d55ca22590b0d7c2c62b9de38ac4a4a7f4687421/gast-0.2.2.tar.gz
Collecting termcolor>=1.1.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Collecting protobuf>=3.6.1 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/65/31/00ba247814289a000f56d89cb0257448efdaa1b79aee62bfb974d0da2e8b/protobuf-3.7.0-cp27-cp27mu-manylinux1_x86_64.whl (1.2MB)
    100% |████████████████████████████████| 1.2MB 1.0MB/s 
Collecting absl-py>=0.1.6 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/31/bc/ab68120d1d89ae23b694a55fe2aece2f91194313b71f9b05a80b32d3c24b/absl-py-0.7.0.tar.gz (96kB)
    100% |████████████████████████████████| 102kB 8.5MB/s 
Collecting tensorboard<1.14.0,>=1.13.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/be/3e/96ace50cf6655f43d3938d81bdb78d941ae7c7e8881685e6cbcce7003082/tensorboard-1.13.0-py2-none-any.whl (3.2MB)
    100% |████████████████████████████████| 3.2MB 6.4MB/s 
Collecting six>=1.10.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting keras-applications>=1.0.6 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/90/85/64c82949765cfb246bbdaf5aca2d55f400f792655927a017710a78445def/Keras_Applications-1.0.7-py2.py3-none-any.whl (51kB)
    100% |████████████████████████████████| 61kB 11.1MB/s 
Collecting grpcio>=1.8.6 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/b8/be/3bb6d8241b5ed1f8437169df53e7dd6ca986174e022585de15087a848c99/grpcio-1.19.0-cp27-cp27mu-manylinux1_x86_64.whl (10.7MB)
    100% |████████████████████████████████| 10.7MB 416kB/s 
Collecting numpy>=1.13.3 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/c4/33/8ec8dcdb4ede5d453047bbdbd01916dbaccdb63e98bba60989718f5f0876/numpy-1.16.2-cp27-cp27mu-manylinux1_x86_64.whl (17.0MB)
    100% |████████████████████████████████| 17.0MB 175kB/s 
Collecting funcsigs>=1; python_version < "3.3" (from mock>=2.0.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/69/cb/f5be453359271714c01b9bd06126eaf2e368f1fddfff30818754b5ac2328/funcsigs-1.0.2-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/14/09/12fe9a14237a6b7e0ba3a8d6fcf254bf4b10ec56a0185f73d651145e9222/pbr-5.1.3-py2.py3-none-any.whl (107kB)
    100% |████████████████████████████████| 112kB 33.4MB/s 
Requirement already satisfied: setuptools in /usr/lib/python2.7/site-packages (from protobuf>=3.6.1->tensorflow) (0.9.8)
Collecting futures>=3.1.1; python_version < "3" (from tensorboard<1.14.0,>=1.13.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl
Collecting werkzeug>=0.11.15 (from tensorboard<1.14.0,>=1.13.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
    100% |████████████████████████████████| 327kB 2.5MB/s 
Collecting markdown>=2.6.8 (from tensorboard<1.14.0,>=1.13.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/7a/6b/5600647404ba15545ec37d2f7f58844d690baf2f81f3a60b862e48f29287/Markdown-3.0.1-py2.py3-none-any.whl (89kB)
    100% |████████████████████████████████| 92kB 546kB/s 
Collecting h5py (from keras-applications>=1.0.6->tensorflow)
  Downloading https://files.pythonhosted.org/packages/53/08/27e4e9a369321862ffdce80ff1770553e9daec65d98befb2e14e7478b698/h5py-2.9.0-cp27-cp27mu-manylinux1_x86_64.whl (2.8MB)
    100% |████████████████████████████████| 2.8MB 20.7MB/s 
Installing collected packages: six, numpy, keras-preprocessing, enum34, astor, backports.weakref, wheel, funcsigs, pbr, mock, absl-py, tensorflow-estimator, gast, termcolor, protobuf, futures, grpcio, werkzeug, markdown, tensorboard, h5py, keras-applications, tensorflow
  Running setup.py install for absl-py ... done
  Running setup.py install for gast ... done
  Running setup.py install for termcolor ... done
Successfully installed absl-py-0.7.0 astor-0.7.1 backports.weakref-1.0.post1 enum34-1.1.6 funcsigs-1.0.2 futures-3.2.0 gast-0.2.2 grpcio-1.19.0 h5py-2.9.0 keras-applications-1.0.7 keras-preprocessing-1.0.9 markdown-3.0.1 mock-2.0.0 numpy-1.16.2 pbr-5.1.3 protobuf-3.7.0 six-1.12.0 tensorboard-1.13.0 tensorflow-1.13.1 tensorflow-estimator-1.13.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.33.1

注:此时安装的为最新版本的TensorFlow1.3.0,若想使用旧版本,可以通过如下指令安装: 
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-x.x.x-cp27-none-linux_x86_64.whl 
x.x.x是你选择的版本号,如0.6.0、0.8.0、1.0.0……

可以通过pip list 查看已经装过的TensorFlow的版本。

5.安装好TensorFlow,可以进行简单的测试,看看是否真的安装成功。 

[root@localhost opt]# python
Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello,World!')
>>> sess = tf.Session()
2019-03-05 05:02:43.911594: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-03-05 05:02:43.917418: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3500000000 Hz
2019-03-05 05:02:43.917757: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x496f120 executing computations on platform Host. Devices:
2019-03-05 05:02:43.917780: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
>>> print sess.run(hello)
Hello,World!
>>> 


看到此,恭喜你。你已经成功的在CentOS7上面部署了TensorFlow,接下来,开始愉快的玩耍吧!!!对于此警告,是因为通过pip直接安装的包没有针对本地环境进行优化,其不影响代码的执行,可以不用管。要是你有强迫症,非要进行处理,可自行设置一下TensorFlow的log显示等级(默认为0–显示所有日志,取值1-3时显示内容递减),快速的方式是在程序中加入如下代码: 
import os 
os.environ[‘TF_CPP_MIN_LOG_LEVEL’]=’2’ 


不过在下次启动时,当前的配置会失效,警告又会出现。一劳永逸的办法就是花个十几二十分钟编译一个健全的TensorFlow。具体的流程会在后续的博客中介绍,敬请期待!!!

参考博客:

1. http://blog.csdn.net/yulei_qq/article/details/52984334 CentOS7下安装python-pip

2. http://www.hankcs.com/ml/compile-and-install-tensorflow-from-source.html从源码编译安装TensorFlow

猜你喜欢

转载自blog.csdn.net/lidew521/article/details/88138268