Tensorflow2.0在windows安装简明教程(防坑)

在我的笔记本上安装tensorflow。
环境:windows10
python版本:3.6

  1. 查询显卡驱动版本是否安装GPU版本的tensorflow
    打开桌面,鼠标右键,打开NVIDIA控制面板,选择左下角系统信息,查看系统显卡驱动版本号。
    参考:点击这里查看详细步骤
  2. 环境准备
    conda 我推荐使用安装miniconda,大家可以理解为精简版的anaconda,只保留了一些必备的组件,所以安装会比快上很多,同时也能满足我们管理python环境的需求。(anaconda一般在固态硬盘安装需要占用几个G内存,花费1-2个小时,miniconda一般几百M,10分钟就可以安装完成了)

windows推荐地址:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.7.10-Windows-x86_64.exe
ubuntu推荐地址:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.7.10-Linux-x86_64.sh
Mac
os推荐地址:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.7.10-MacOSX-x86_64.pkg

下载好后以管理员权限打开点击安装

  1. TF CPU安装
    TF CPU安装比较简单,因为不需要配置GPU,所以windows ubuntu macOS安装方式都类似,缺点就是运行速度慢,但是用于日常学习使用还是可以的。
    下面以windows版本做演示:一下均在命令行操作

  2. 新建TF2.0 CPU环境(使用conda 新建环境指令 python==3.6表示在新建环境时同时python3.6)

conda create -n TF_2C python=3.6
  1. 输入y回车
    当弹出 :Proceed ([y]/n)? 输入y回车
  2. 进入TF_2C环境
conda activate TF_2C

进入后我们就可以发现:(TF_2C)在之前路径前面,表示进入了这个环境。使用conda deactivate可以退出。

  1. 安装TF2.0 CPU版本(后面的 -i 表示从国内清华源下载,速度比默认源快很多)
pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 测试TF2.0 CPU版本
    (把下面代码保存到demo.py使用python打开运行)
import tensorflow as tf
version = tf.__version__
gpu_ok = tf.test.is_gpu_available()  #这一步可以注释掉,打印时也删掉就行
print("tf version:",version,"\nuse GPU",gpu_ok)

如果没有问题的话输出结果如下:可以看到tf 版本为2.0.0 因为是cpu版本,所以gpu 为False

tf version: 2.0.0
use GPU False
  1. TF2.0 GPU版本安装
conda create -n TF_2G python=3.6
conda activate TF_2G
conda install cudatoolkit=10.0 cudnn
pip install tensorflow-gpu==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 同cpu进行测试
  2. 参考网址:点击这里查看安装详情

相关注意的地方

  • 镜像问题
 #优先命名用清华conda 镜像
conda config --prepend channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

安装pip install --upgrade --ignore-installed tensorflow-gpu会出现

Cache entry deserialization failed, entry ignored

解决:管理员权限打开anaconda prompt之后再安装就没问题

  • 安装tensorflow提示Requirement already satisfied
    Requirement already satisfied: funcsigs>=1; python_version < “3.3” in /usr/local/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow-gpu==1.4) (1.0.2)

解决办法:

输入以下命令

扫描二维码关注公众号,回复: 9718286 查看本文章
pip install --upgrade --ignore-installed -i https://pypi.mirrors.ustc.edu.cn/simple tensorflow-gpu==2.0

或者

pip install --upgrade --ignore-installed -i tensorflow-gpu==2.0 https://pypi.mirrors.ustc.edu.cn/simple 

直接无视之前版本就行了。问题解决。

由于我的显卡比较老,安装最新的tensorflow-gpu尚未成功,但是成功安装了cpu版本,也能用,接下来就是学习的过程了。

发布了65 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/heroybc/article/details/102413424
今日推荐