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/tensorflow-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))
总结:
总体来说Tensorflow的安装还是比较简单的, 有如下几个小细节是需要注意的,我一开始安装的时候,就被困扰了好久。
1. Anaconda 需要先准备Tensorflow环境 conda create -n tensorflow python=3.5
2. 需要升级pip版本, Anaconda自带的pip无法安装tensorflow pip install -U pip
3. windows 下莫名的安装特别慢, 一定要善于使用国内的景象安装,比如https://mirrors.tuna.tsinghua.edu.cn/