1. 下载 Anaconda
在 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 寻找你与你电脑系统对应的版本,我这里使用 Anaconda3-4.2.0-Windows-x86_64.exe
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86_64.exe
下载并安装完成后,打开 CMD, 输入 'conda --version', 如果输出如下信息
conda 4.2.0
Anaconda 安装成功。
接下来需要设置 Anaconda 仓库镜像,因为默认连接的是国外镜像地址,下载速度比较慢,我们把镜像地址改为清华大学开源软件镜像站,打开 Anaconda Prompt, 输入:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
2.安装 TensorFlow
继续在 Anaconda Prompt 窗口输入:
conda create -n tensorflow python=3.5
按回车。
表示创建 TensorFlow 依赖环境,TensorFlow 目前不支持Python3.6,这里我们使用Python3.5。
继续看控制台输出:
Fetching package metadata ...............
Solving package specifications: .
Package plan for installation in environment D:\Program Files\anaconda\envs\tensorflow:
The following NEW packages will be INSTALLED:
pip: 9.0.1-py35_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
python: 3.5.3-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
setuptools: 27.2.0-py35_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
vs2015_runtime: 14.0.25123-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
wheel: 0.29.0-py35_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
Proceed ([y]/n)? y
提示我们安装哪些依赖软件,输入‘y’,回车。
控制台继续输出:
python-3.5.3-0 100% |###############################| Time: 0:00:42 754.91 kB/s
setuptools-27. 100% |###############################| Time: 0:00:00 1.92 MB/s
wheel-0.29.0-p 100% |###############################| Time: 0:00:00 2.68 MB/s
pip-9.0.1-py35 100% |###############################| Time: 0:00:00 2.31 MB/s
#
# To activate this environment, use:
# > activate tensorflow
#
# To deactivate this environment, use:
# > deactivate tensorflow
#
# * for power-users using bash, you must source
#
开始下载安装依赖软件,我这里使用的是清华大学镜像仓库,所以下载速度很快。
安装 CPU 版本:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ https://mirrors.tuna.tsinghua.edu.cn/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl
如果控制台最终输出 如下信息表示安装成功。
你也可以打开 https://mirrors.tuna.tsinghua.edu.cn/tensorflow/ 选择合适的 whl 文件地址进行安装;或者打开https://mirrors.tuna.tsinghua.edu.cn/help/tensorflow/ 可视化选择 whl 版本。
Successfully installed numpy-1.12.1 protobuf-3.3.0 six-1.10.0 tensorflow-1.1.0 werkzeug-0.12.2
继续输入:
activate tensorflow
激活 TensorFlow 虚拟环境,当不使用 TensorFlow 时,使用 deactivate tensorflow 关闭。
3.测试
进入到 Anaconda 安装目录下 /envs /tensorflow 文件夹,继续在 Anaconda Prompt 窗口输入输入:
python.exe
回车后,复制复制如下内容拷贝到Anaconda Prompt,自动输出:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
>>> sess.run(hello)
>>> a = tf.constant(10)
>>> b= tf.constant(32)
>>> sess.run(a+b)
>>>
输出:
...
b'Hello, TensorFlow!'
...
42
表示 TensorFlow 已经安装成功。