windows安装tensorflow-gpu.报错Could not load dynamic library ‘cudart64_110.dll

  • 遇到情况是:
    电脑上滴啊有GPU,但是安装时没在意,安装的是cpu版本,重新卸载安装。
    在这里插入图片描述
    解决错误中用到的命令:
  • tf查看版本
 tf.__version__

卸载windows下的tensorflow-cpu

在cmd中转换到python下的pip,或者安装有git,直接代开即可
输入
pip uninstall tensorflow

直接没有
如果是之前装的gpu,卸载gpu版本,则需要加后缀。

pip uninstall tensorflow-gpu

在这里插入图片描述

  • 删除残留文件
    卸载完后会有残留文件也需要删除,在利用上面安装路径命令,查看安装位置
  • tf查看安装位置
 tf.__path__
  • 删除所有带有tensor的文件夹

接下来将如何安装windows的gpu版本tensorflow

之前有过经验的应该知道,gpu版本的多种框架pytorch、tensorflow安装cuda。

安装cuda具体步骤可参考https://blog.csdn.net/qq_41760767/article/details/97444053

因之前安装过pytorch,已有cuda的可按以下来:
1)按win+Q,输入控制面板,然后查看方式小图标,点击NVIDIA控制面板:
在这里插入图片描述
在这里插入图片描述
2)第二种方式是:

打开CMD,输入nvcc --version
在这里插入图片描述

安装

  • 安装时一定要根据自己的python、cuda版本安装对应的tensorflow版本
  • 最好是安装前先选好版本,再去安装对应环境下的cuda、python
    在这里插入图片描述
pip install tensorflow-gpu

在这里插入图片描述

在这里插入图片描述
安装完成

测试一下

python文件

import tensorflow as tf

# Creates a graph.
with tf.device('/device:GPU:2'):
  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
  b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
  c = tf.matmul(a, b)
# Creates a session with allow_soft_placement and log_device_placement set
# to True.
sess = tf.Session(config=tf.ConfigProto(
      allow_soft_placement=True, log_device_placement=True))
# Runs the op.
print(sess.run(c))

在这里插入图片描述
又白高兴了,这个问题应该是cuda版本不够安装2.4.1,去查一下发现:
最新版本要求cuda在11.0了,卸载重装一个2.2试一下
在这里插入图片描述

在这里插入图片描述

还是没解决。继续找找,现在不一样的就是cuda我的是10.2之前安好的,但是tensor官网上没有相应的版本,不过我之前也装过cuda10.0,版本转换试一下。

cuda版本转换

我的电脑右击属性
在这里插入图片描述

  • 改完后
    在这里插入图片描述

  • 验证deviceQuery和bandwidthTest

  • 在命令窗口运行测试文件,定位到 在cuda安装目录的 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\demo_suite,分别输入deviceQuery.exe,bandwidthTest.exe并运行,两个地方的Result=PASS则说明通过,反之,Rsult=Fail 则需要重新安装。

在这里插入图片描述
最终有没有很好地解决,不过因为只是生成下文件,cpu的也能使用,不用他用于训练,也懒得整了。
至于原因应该是,cuda、python与tensorflow的版本不一致导致的,我的Python是3.8的,cuda是10.0或者10.2,因此没有合适版本的tensorflow


因此最最重要的一定要看好版本再着手装。

猜你喜欢

转载自blog.csdn.net/weixin_42535423/article/details/116017282