Anaconda Tensorflow 安装
1: anaconda 下载
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
选择 3.4.2 的版本
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86_64.exe
2: 设置 Conda 的镜像包地址
使用管理员方式运行 cmd
运行命令
C:\>conda config --add channels
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
C:\>conda config --set show_channel_urls yes
检验:
当前用户路径下会生成如下文件
C:\Users\Administrator\ .condarc
文件内容如下:
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
注释:默认是 conda 的景象都是国外的,有可能非常慢,导致多次无法成功
3: 使用 conda 准备 tensorflow 的环境
使用管理员运行 cmd
C:\ >conda create -n tensorflow python=3.5
注释: python 有 2.7
3.4
3.5 这 3 个版本可以选,我们这里使用 3.5
4:升级 pip 命令
使用管理员运行 cmd 执行如下命令
C:\ > pip install -U pip
注释:因为使用 pip 安装 tensorflow 要求,pip 是 9.0.1 版本的,但是 anaconda
默认的版本是 8.1.2,所以需要自行此命令升级
5:安装 tensorflow
介于国内很容易下载失败,建议使用国内的景象安装
使用管理员运行 cmd 执行如下命令
C:\ > pip install
https://mirrors.tuna.tsinghua.edu.cn/tensorflow/windows/cpu/tensorfl
ow-1.3.0rc0-cp35-cp35m-win_amd64.whl
注释: 有哪些景象可以在如下地址找到
https://mirrors.tuna.tsinghua.edu.cn/tensorflow
默认安装命令
C:\ > pip install tensorflow
C:\ > Pip install tensorflow-gpu
6: 验证是否安装成功
6.1 设置 jupyter 的工作路径
使用管理员运行 cmd 命令
C:\Users\hechangfu>jupyter notebook --generate-config
命令提示:
Writing default config to:
C:\Users\Administrator\.jupyter\jupyter_notebook_config.py
找到:jupyter_notebook_config.py 并打开
## The directory to use for notebooks and kernels.
#c.NotebookApp.notebook_dir = ''
将上述修改为
c.NotebookApp.notebook_dir = 'g:\python_training'
6.2 使用 jupyter 编写 tensorflow python 代码
使用管理员运行 cmd 命令
C:\ >jupyter notebook
启动 python 编辑器 jupyter , 这时候会弹出 web 界面
1. 创建 python 文件
2. 写一个 tensorflow 的 hello world
import tensorflow as tf
hello = tf.constant("hello world")
sess = tf.Session()
print (sess.run(hello))
a = tf.constant("hello")
b = tf.constant(" ")
c = tf.constant("world");
print (sess.run(a+b+c))