简单 TensorFlow 2 anaconda安装教程 示例

一、安装anaconda

https://www.anaconda.com/products/individual#Downloads
anaconda官网下载,安装即可
如果下载慢的话,更换到清华源
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

二、更换anaconda源

在Anaconda Prompt (Anaconda3)运行命令

conda config --set show_channel_urls yes

如图所示
在这里插入图片描述

编辑Windows 用户目录下的**.condarc**文件
在这里插入图片描述
粘贴如下并保存

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

在Anaconda Prompt (Anaconda3)运行命令

conda clean -i

如图所示
在这里插入图片描述

三 安装TensorFlow

在 Anaconda Powershell Prompt (Anaconda3)创建虚拟环境并进入

 conda create -n tensorFlow 

在这里插入图片描述
切换环境

conda activate tensorFlow 

安装英伟达cudatoolkit驱动

conda install cudatoolkit

安装英伟达cudnn驱动

conda install cudnn=7.6.5

安装tensorflow

conda install tensorflow 

三、测试案例

在 Anaconda Powershell Prompt (Anaconda3)输入python 进入编辑命令
粘贴如下

import tensorflow as tf

A = tf.constant([[1, 2], [3, 4]])
B = tf.constant([[1, 2], [3, 4]])
C = tf.matmul(A, B)

print(C)

输出如下

tf.Tensor(
[[ 7 10]
 [15 22]], shape=(2, 2), dtype=int32)

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值