在win10上安装 Tensorflow

Tensorflow 有很多种安装方式,而且在每个平台或者同一平台有GPU和无GPU的,甚至不同GPU的安装方式也有所不同。这里只以win10 系统为安装环境来说明。

下载软件包

安装 redistributable 和 Python

  • Visual C++ 2015 redistributable Python-3.5.0-amd64双击按提示操作就可以安装完成,很简单,这里就不说明安装过程了
  • 打开Windows PowerShell,输入python
PS C:\Users\wave>python  
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32  
Type "help", "copyright", "credits" or "license" for more information.  
>>>

看到以上信息,说明Python安装成功

安装Tensorflow

PS C:\Users\wave> pip install --upgrade C:\Users\wave\Downloads\tensorflow-1.1.0-cp35-cp35m-win_amd64.whl  
tensorflow-1.1.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.  
You are using pip version 7.1.2, however version 9.0.1 is available.  
You should consider upgrading via the 'python -m pip install --upgrade pip' command.  

直接安装会出错,出错信息为 tensorflow-1.1.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.

那要怎么办呢,主要是pip的版本太低,按提示升级

PS C:\Users\wave> python -m pip install --upgrade pip  

重新运行

PS C:\Users\wave> pip install --upgrade C:\Users\wave\Downloads\tensorflow-1.1.0-cp35-cp35m-win_amd64.whl  

可以看到 说明安装成功

编写一个Hello world

直接使用 tensorflow 上的例子

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)

在发现运行 sess = tf.Session()会出现以下信息

2017-05-20 08:13:10.366444: W c:\tfjenkins\home\workspace\nightly-win\device\cpu\os\windows\tensorflow\core\platform\cpufeature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE i
nstructions, but these are available on your machine and could speed up CPU computations.
这样的警告信息,不用管它也是可以接着运行正常

如果觉得不舒服,可以设置Tensorflow的日志级别使其关闭

import os  
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'