基于Tensorflow框架的深度学习环境搭建(包括解决pip下载包慢的问题)


此环境搭建是在Windows10系统上进行的,组合为anaconda2019. 10+tensorflow2. 1+pycharm。遇坑太多,以此纪念。

1. 安装Anaconda3

官网下载Anaconda2019.10,安装,将anaconda3加入环境变量

2. TensorFlow的安装

2.1 创建TF2.1环境

开始屏幕打开anaconda prompt 输入:conda create -n TF2.1 python=3.7, 选择y表示同意安装相关软件包

在这里插入图片描述
激活环境
在这里插入图片描述

2.2 安装cudatoolkit10.1以及cudnn7.6

在这里插入图片描述在这里插入图片描述

如果报错说明电脑上没有英伟达显卡,直接跳过2.2 ,进入2.3

2.3 安装tensorflow2.1

继续输入pip install tensorflow==2.1 大小大约是350MB,运行到这里大概你就会发现电脑下载很慢,所以我们要选择镜像源,这里我用的是清华镜像。我们只需要对电脑上的.condaarc文件进行修改即可。
Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。
用记事本打开C盘用户管理员下的.condaarc文件,这里我是C:\Users\ASUS\.condaarc,输入以下代码块:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - 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/pro
  - 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

保存后,运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。重新安装发现会很快。

3. Pycharm新建工程,写入代码进行验证

3.1 安装pycharm

官网直接下载,用社区版就行,最新版
在这里插入图片描述
安装过后重启电脑

3.2 创建项目

选择已存在的解释器,设置环境变量
在这里插入图片描述
点击已经存在的anaconda环境,会自动跳出来TF2.1
在这里插入图片描述
点击create,创建成功。

3.3 测试环境

创建test.py
测试代码如下:

import tensorflow as tf

tensorflow_version = tf.__version__
gpu_available = tf.test.is_gpu_available()
print("tensorflow version", tensorflow_version, "\tGPU available", gpu_available)
a = tf.constant([1.0, 2.0], name="a")
b = tf.constant([1.0, 2.0], name="b")
result = tf.add(a, b, name="add")
print(result)

测试成功,环境搭建完成!准备开始下一步学习吧!

课程指导:北大的tensorflow笔记

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值