Windows7 64位安装TensorFlow

参考TensorFlow官网的Windows安装步骤(https://www.tensorflow.org/install/install_windows

首先安装Python 3.5

官网地址: https://www.python.org/downloads/release/python-352/

然后安装TensorFlow

打开命令提示符,输入

  • CPU版本:

    pip install tensorflow

  • GPU版本:

    pip install tensorflow-gpu

因为我的电脑不支持GPU版本,所以安装CPU版本。

如果安装过程提示下述错误:

You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

这是由于Python 3.5自带的pip版本是8.1.1,而TensorFlow需要的是9.0.1版本,因此需要升级pip,可以通过下述命令升级

python -m pip install --upgrade pip

但是国内需要fq(你懂得),所以可能会出现下述连接超时错误

pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.

这时应该选择使用国内源来免fq升级pip,如清华源:https://pypi.tuna.tsinghua.edu.cn/simple

临时使用国内可以加上参数-i https://pypi.tuna.tsinghua.edu.cn/simple

如:python -m pip install –upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple,这样就使用清华源来升级pip,速度很快,命令提示符显示如下,升级成功:

C:\Users\Brian>python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua
.edu.cn/simple
Collecting pip
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b6/ac/7015eb97dc749283f
fdec1c3a88ddb8ae03b8fad0f0e611408f196358da3/pip-9.0.1-py2.py3-none-any.whl (1.3M
B)
    35% |███████████▎                    | 440kB 1.6MB/s eta 0:00:01
    ......
    100% |████████████████████████████████| 1.3
B 517kB/s
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
      Successfully uninstalled pip-8.1.1
Successfully installed pip-9.0.1

也可以一直使用国内源:

在C:\Users\用户名\目录中创建一个pip目录,并且在匹配目录中新建文件pip.ini,内容如下:

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = mirrors.aliyun.com

安装numpy

pip3 install numpy

numpy是Python的数值计算扩展工具,Tensorflow的脚本是基于numpy的

现在再安装TensorFlow

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow

很快就可以安装完成。

这里写图片描述

测试TensorFlow是否安装成功

打开Python 3.5的终端,输入以下代码:

>>> import tensorflow as tf  
>>> hello = tf.constant('Hello, World!')  
>>> sess = tf.Session()  
>>> print(sess.run(hello))  
Hello, World!  
>>> a = tf.constant(1)  
>>> b = tf.constant(2)  
>>> print(sess.run(a + b))  
3  
>>  

至此TensorFlow安装成功。

作者:lb377463323
出处:http://blog.csdn.net/lb377463323
原文链接:http://blog.csdn.net/lb377463323/article/details/77118361
转载请注明出处!

猜你喜欢

转载自blog.csdn.net/lb377463323/article/details/77118361