利用Anaconda搭建TensorFlow环境并在Jupyter Notebook使用

打开Anaconda Prompt

利用Anaconda搭建TensorFlow环境并在Jupyter Notebook使用_第1张图片

创建一个tensorflow 虚拟环境:

conda create -n tensorflow python=3.6

激活tensorflow虚拟环境

activate tensorflow

查找当前可用的tensorflow包

anaconda search -t conda tensorflow
利用Anaconda搭建TensorFlow环境并在Jupyter Notebook使用_第2张图片
利用Anaconda搭建TensorFlow环境并在Jupyter Notebook使用_第3张图片
这里写图片描述

根据提示,查看一个包的详情信息

anaconda show anaconda/tensorflow
利用Anaconda搭建TensorFlow环境并在Jupyter Notebook使用_第4张图片

根据提示,copy命令安装tensorflow

conda install –channel https://conda.anaconda.org/anaconda tensorflow

查看环境,确认安装是否成功

conda info –envs
利用Anaconda搭建TensorFlow环境并在Jupyter Notebook使用_第5张图片

也可以测试一下

python
import tensorflow as tf
hello = tf.constant(‘hello,Tensorflow!’)
session = tf.Session()
print(session.run(hello))
至此,完成了tensorTensorFlow的安装,但是要在jupyter notebook中用的话还需要下面的操作

jupyter中使用TensorFlow

在激活TensorFlow之后安装ipython和jupyter

(tensorflow)D:>conda install ipython
···
(tensorflow)D:>conda install jupyter
···
安装python kernel for Tensroflow

(tensorflow)D:>ipython kernelspec install-self –user #不要复制这个命令,user前面是两个-,这里显示不出来

看到类似如下结果

Installed kernelspec python3 in C:\Users\XXX\Jupyter\kernels\python3

打开Jupyter notebook

试试 import tensorflow as tf

你可能感兴趣的:(Tensorflow)