对于tensorflow的安装步骤,大家应该都不陌生,官方支持多种安装方式包括pip,docker等。但是在很多场景下,都是在内网安装,无法通过在线安装。在网上搜了很多资料,其中包括支持源代码编译的方法,但都比较复杂。因此总结了一下离线安装的方法,主要是通过pip安装本地whl文件的方法,从坑里刚爬出来,希望有用 :)
1. 检查是否安装pip,如果没有安装,下载pip安装包,pip-9.0.1.tar.gz,解压,使用python setup.py install 安装。
2. 下载tensorflow-0.12.1-cp27-none-linux_x86_64.whl, 此安装包为python2.7对应的版本 (如果python版本为3.5则需要下载相应的安装包)
3. 使用 pip install tensorflow-0.12.1-cp27-none-linux_x86_64.whl 命令安装,在安装过程中会检查缺少依赖包,因为是离线环境,所以需要手动下载安装包,在https://pypi.python.org/pypi 搜索并下载缺失的依赖包,使用 python setup.py install 方法依次安装. 以下为一些可能需要的依赖包名称:
- protobuf-3.2.0.tar.gz
- six-1.10.0.tar.gz
- wheel-0.30.0a0.tar.gz
- mock-2.0.0.tar.gz
- setuptools-34.3.0.zip
- packaging-16.8.tar.gz
- pyparsing-2.1.10.tar.gz
- appdirs-1.4.2.tar.gz
- pbr-1.10.0.tar.gz
- numpy-1.12.0.zip
- funcsigs-1.0.2.tar.gz
[root@ochadoop03 ~]# pip install tensorflow-0.12.1-cp27-none-linux_x86_64.whl
Processing ./tensorflow-0.12.1-cp27-none-linux_x86_64.whl
Requirement already satisfied: protobuf>=3.1.0 in /usr/lib/python2.7/site-packages/protobuf-3.2.0-py2.7.egg (from tensorflow==0.12.1)
Requirement already satisfied: six>=1.10.0 in /usr/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from tensorflow==0.12.1)
Requirement already satisfied: wheel in /usr/lib/python2.7/site-packages/wheel-0.30.0.a0-py2.7.egg (from tensorflow==0.12.1)
Requirement already satisfied: mock>=2.0.0 in /usr/lib/python2.7/site-packages (from tensorflow==0.12.1)
Requirement already satisfied: numpy>=1.11.0 in /usr/lib64/python2.7/site-packages/numpy-1.12.0-py2.7-linux-x86_64.egg (from tensorflow==0.12.1)
Requirement already satisfied: setuptools in /usr/lib/python2.7/site-packages/setuptools-34.3.0-py2.7.egg (from protobuf>=3.1.0->tensorflow==0.12.1)
Requirement already satisfied: funcsigs>=1 in /usr/lib/python2.7/site-packages/funcsigs-1.0.2-py2.7.egg (from mock>=2.0.0->tensorflow==0.12.1)
Requirement already satisfied: pbr>=0.11 in /usr/lib/python2.7/site-packages (from mock>=2.0.0->tensorflow==0.12.1)
Requirement already satisfied: packaging>=16.8 in /usr/lib/python2.7/site-packages/packaging-16.8-py2.7.egg (from setuptools->protobuf>=3.1.0->tensorflow==0.12.1)
Requirement already satisfied: appdirs>=1.4.0 in /usr/lib/python2.7/site-packages/appdirs-1.4.2-py2.7.egg (from setuptools->protobuf>=3.1.0->tensorflow==0.12.1)
Requirement already satisfied: pyparsing in /usr/lib/python2.7/site-packages/pyparsing-2.1.10-py2.7.egg (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow==0.12.1)
Installing collected packages: tensorflow
Successfully installed tensorflow-0.12.1
4. tensorflow验证
-
进入python shell,import tensorflow包查看是否报错。
import tensorflow as tf
执行mnist例子如下, 注意,因为是隔绝外网的环境,需要手动下载mnist data数据,并将下载的数据放到 $mnist_dir/data下
[root@ochadoop03 mnist]# python convolutional.py
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
Initialized!
Step 0 (epoch 0.00), 2.9 ms
Minibatch loss: 8.334, learning rate: 0.010000
Minibatch error: 85.9%
Validation error: 84.6%