Windows10下用Anaconda安装Tensorflow

well,今日 文 艺 复 兴 ,安个老一点的Tensorflow。

1、卸载已有的Tensorflow

activate tensorflow	 #这个tensorflow是虚拟环境的名字
pip uninstall tensorflow

之后会出现这个

Proceed (y/n)? y

写 y 就好了

之后打开Anaconda
Environment -> tensorflow(之前虚拟环境的名字) ->Remove(在最下面)
删除tensorflow这个环境
Windows10下用Anaconda安装Tensorflow_第1张图片

2、开始安装

1、检测anaconda环境是否安装成功
在cmd中输入:conda --version
2、检测目前电脑安装了哪些环境变量
在cmd中输入:conda info --envs
3、查看当前有哪些可以使用的tensorflow版本
在cmd中输入:conda search --full-name tensorflow
注意命令中 --full 和 -name之间没有空格
4、建立一个 conda 计算环境,创建一个专门的虚拟环境(env),命名为 tensorflow,并安装python3.7
在cmd中输入:

conda create --name tensorflow python=3.6

之后会出现这个Proceed ([y]/n)?写 y 即可
Windows10下用Anaconda安装Tensorflow_第2张图片
出现上图则安装成功

5、激活tensflow的虚拟环境
在cmd中输入: activate tensorflow
检测tensorflow的环境是否添加到了Anaconda里面,我们来查看系统环境
在cmd中输入:conda info --envs
在这里插入图片描述
出现了tensorflow则环境添加成功

6、之后安装Tensorflow
先退出tensorflow虚拟环境,回到base

conda deactive

添加清华的源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

之后回到tensorflow虚拟环境

activate tensorflow

以上步骤如下图所示
Windows10下用Anaconda安装Tensorflow_第3张图片
下面正式安装:
注意指定版本

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.12.0

在这里插入图片描述
有了这个successfully…就成功了

7、验证一下功能是否正常:

进入代码环境,在cmd中输入:python

输入测试代码:

import tensorflow as tf
hello = tf.constant(‘hello,tf’)
sess = tf.Session()
print(sess.run(hello))

看到如下结果,说明该环境下 tensorflow 工作正常。
在这里插入图片描述
整个过程如下:

(tensorflow) C:\Users\Q>python 		#这是第一条命令
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf				 #这是第二条命令
D:\Anacoda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\Anacoda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\Anacoda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\Anacoda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\Anacoda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\Anacoda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
>>> hello = tf.constant('hello,tf')			#这是第三条命令
>>> sess = tf.Session()					 #这是第四条命令
2020-04-24 14:15:50.881287: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
>>> print(sess.run(hello))			#这是第五条命令
b'hello,tf'								#成功
>>>

退出python的命令为exit()

你可能感兴趣的:(Tensorflow,anaconda,tensorflow)