tensorflow2.6.0 安装教程 windows10
Posted SevenBerry
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tensorflow2.6.0 安装教程 windows10相关的知识,希望对你有一定的参考价值。
更新CUDA驱动
此处可参考:如何在windows上 安装&更新 显卡的驱动
建议将cuda driver(显卡驱动)升级到最新版本,这样cuda runtime版本可以有更多选择
(1)进入英伟达官网下载驱动:https://www.nvidia.cn/Download/index.aspx?lang=cn
选择GPU型号对应的NVIDIA驱动(可在“任务管理器”查看)
“产品系列”中,(Notebook) 表示为笔记本上的显卡驱动;下载类型选择默认的Game Ready 驱动程序
![](https://image.cha138.com/20230303/c7a3d8dac7d145b4ae14508cd32418d8.jpg)
点击上图中的“搜索”,进入下图界面后点击“下载”(跳转后点击“同意并开始下载”)
![](https://image.cha138.com/20230303/c50bdc39e5504d57a748791aff07a644.jpg)
下载完成后,双击exe运行安装,安装位置选择默认即可
![](https://image.cha138.com/20230303/bf9ec3f893604aaf83582d5f3c16b4e3.jpg)
安装完成后,会进入NVIDIA图形驱动程序界面,
依次点击“同意并继续”--> "精简(推荐)" 进入安装,
安装完后,最后的界面全部取消勾选
(2)打开命令行cmd,使用 nvidia-smi 查看 cuda driver 版本
![](https://image.cha138.com/20230303/1c16c565de064870ad959cbe1a5c6af8.jpg)
2. 安装cuda runtime
此处可参考:详细讲解如何在win10系统上安装多个版本的CUDA
(1)进入官网选择适合的cudatoolkit版本:https://developer.nvidia.com/cuda-toolkit-archive
注意cuda runtime版本不应该超过cuda driver版本
![](https://image.cha138.com/20230303/4f2c043daca34a27beff24c815ad15d5.jpg)
选择exe(local) 下载本地,安装程序可默认安装在C盘,CUDA安装位置可自己选择(D盘)
![](https://image.cha138.com/20230303/dd6bbba5070a482597c50e1c20f949cb.jpg)
(2)打开命令行cmd,使用 nvcc -V 查看cuda runtime 版本
![](https://image.cha138.com/20230303/3faeac1b815c434da4d8a9dabedaf5b8.jpg)
(3)安装cudnn
进入官网下载cudatoolkit对应版本的cudnn(下载需注册):https://developer.nvidia.com/rdp/cudnn-archive
![](https://image.cha138.com/20230303/6e18c32fe6474627a6890aaa1a5c033b.jpg)
将下载的zip文件解压,解压后将其中的bin、include、lib三个文件,复制粘贴到cudatoolkit的安装位置
![](https://image.cha138.com/20230303/a8b64dac90814dd1bd5e6f9ef79dd509.jpg)
![](https://image.cha138.com/20230303/e922a5e7199d4466a0cc5e01332a07bc.jpg)
(4)查看cudnn版本
打开cudatoolkit安装路径下的\\include\\cudnn_version.h文件
![](https://image.cha138.com/20230303/832417f7213c4b9bb5e443961b7e0acf.jpg)
cudnn版本即为cudnn_majar . cudnn_minor . cudnn_patchevel
![](https://image.cha138.com/20230303/3b7d93e00c984b638c41e5edf64a5192.jpg)
(5)设置环境变量
![](https://image.cha138.com/20230303/0d7cc6a15719489b9b7d51c74e1c9659.jpg)
![](https://image.cha138.com/20230303/25d8f54bbc4642bbaca04435da949e0b.jpg)
当存在多个cudatoolkit版本时,下图Path中需将当前使用的版本放在其他版本前面,
![](https://image.cha138.com/20230303/e659b46b6ce849feba012ded9604671c.jpg)
3. 安装tensorflow2.6.0
(1)打开 Anaconda Prompt,创建虚拟环境
conda create -n tensorflow python=3.8
(2)激活虚拟环境
conda activate tensorflow
(3)安装tensorflow-gpu版本(已集成keras),使用豆瓣镜像源加速
pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simple/
(4)安装相同版本的keras
pip install keras==2.6.0 -i https://pypi.douban.com/simple/
(5)验证是否安装成功
python
import tensorflow as tf
tf.test.is_gpu_available()
最后一句输出能 "True" 即为GPU版本安装成功
![](https://image.cha138.com/20230303/e5389eb15a6c48479da59b81b59938ab.jpg)
【问题解决】
(1)导入tensorflow时, import tensorflow as tf 报错
“TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.”
![](https://image.cha138.com/20230303/62ab7b8b02a441d395d853d3f468a28d.jpg)
解决办法:
在Anaconda Prompt中安装3.19.0版本的protobuf
pip install protobuf==3.19.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
再次import tensorflow as tf 即可导入成功
![](https://image.cha138.com/20230303/17407b9c760c426c8c91bf07510a0e4e.jpg)
(2)tf.test.is_gpu_available() 返回False,检测GPU不可用
“W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2023-02-13 10:17:13.673996: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1835] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...”
![](https://image.cha138.com/20230303/4f0eafd04afa4012bf512ad6a587bf54.jpg)
解决办法:
1)既然找不到cudnn64_8.dll文件,那就去下载一个dll文件https://www.dll-files.com/search/
下载完成后,将其移动到cudatoolkit安装路径下的Development\\bin文件夹中
(其实就是NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\bin中的cudnn64_8.dll文件)
![](https://image.cha138.com/20230303/0f04b1e9a10b4bfdada828020c22c448.jpg)
2)或者,在“编辑系统环境变量”中,将cudatoolkit\\bin文件夹的安装路径D:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.3\\bin添加到Path变量中(我试的无效)
![](https://image.cha138.com/20230303/7a44710a686044da8ff3bf0028b6c20c.jpg)
此处可参考tensorflow官网:https://www.tensorflow.org/install/gpu?hl=zh-cn
![](https://image.cha138.com/20230303/5b30b06aed7f49ecbb6386d0436bcfeb.jpg)
以上是关于tensorflow2.6.0 安装教程 windows10的主要内容,如果未能解决你的问题,请参考以下文章
ES系统封装教程 高级进阶版 提供Wind7,xp系统下载 (by 星空武哥)