问题描述
在 Windows 系统安装并导入 TensorFlow 后,运行时出现如下警告:
2025-04-01 09:45:29.361309: W tensorflow/stream_executor/platform/default/dso_loader.cc:64]
Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
虽然程序仍能运行,但无法调用 GPU 加速,严重影响训练效率。
原因分析
-
CUDA 版本不匹配:该报错表明 TensorFlow 需要 CUDA 11.0 的运行时库(
cudart64_110.dll
),但系统中未找到,我本地是 12.1 版本的 CUDA。 -
环境配置缺失:可能未正确安装 CUDA 工具包或环境变量未配置。
-
TensorFlow 版本限制:从TensorFlow 2.11开始,Windows 原生环境不再支持 GPU,必须使用 WSL2。
解决方案
通过 Conda 安装匹配的 CUDA 和 cuDNN(以TensorFlow 2.10.0为例),Anaconda 允许在虚拟环境中通过 conda install
安装特定版本的 cuda
和 cudann
,这些库仅对当前环境生效,不会影响系统全局的CUDA安装。
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
验证安装
import tensorflow as tf
print(tf.config.list_physical_devices('GPU')) # 检查GPU是否可用