一. 利用anaconda图形界面
1.打开Anaconda Navigator,创建新环境tensorflow
2.选择keras tensorflow
3.在tensorflow环境下安装spyder / jupyter notebook
二. 利用命令行
conda create -n tensor python=3.6
##很多情况下网速太慢导致图形界面和命令行创建环境都失败,这时需要修改.condarc文件
win+R
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
show_channel_urls: true
ssl_verify: true
conda install spyder
三.测试
1. 输出为3,tensorflow安装成功
import tensorflow as tf
sess = tf.Session()
a = tf.constant(1)
b = tf.constant(2)
print(sess.run(a+b))
2.如下输出
输出为:
Tensor("add_1:0", shape=(), dtype=float32)
GPU: True
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)
print('GPU:', tf.test.is_gpu_available())