You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyCharm运行代码报DNN library is not found错误,终端执行正常

PyCharm中TensorFlow Conv2D报错"DNN library is not found"的排查与解决

问题背景

执行pip install waymo-open-dataset-tf-2-6-0 --user安装Waymo数据集后,TensorFlow被自动从2.11降级到2.6。恢复TensorFlow 2.11版本后,代码在终端运行完全正常,但在PyCharm中执行时触发如下报错:

11/Mar/23 13:07:49 - utils.aux_funcs - ERROR - Exception encountered when calling layer 'conv2d' (type Conv2D).

{{function_node __wrapped__Conv2D_device_/job:localhost/replica:0/task:0/device:GPU:0}} DNN library is not found. [Op:Conv2D]

Call arguments received by layer 'conv2d' (type Conv2D):
  • inputs=tf.Tensor(shape=(64, 128, 128, 1), dtype=float32)
Traceback (most recent call last):
  File "/home/USER/projects/QANetV2/qanet/tf_train.py", line 87, in <module>
    trained_model = train_model(
  File "/home/USER/projects/QANetV2/qanet/tensor_flow/utils/tf_utils.py", line 484, in train_model
    model.fit(
  File "/home/USER/anaconda3/envs/qanet/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/USER/projects/QANetV2/qanet/tensor_flow/custom/tf_models.py", line 208, in call
    return self.model(inputs)
tensorflow.python.framework.errors_impl.UnimplementedError: Exception encountered when calling layer 'conv2d' (type Conv2D).

{{function_node __wrapped__Conv2D_device_/job:localhost/replica:0/task:0/device:GPU:0}} DNN library is not found. [Op:Conv2D]

Call arguments received by layer 'conv2d' (type Conv2D):
  • inputs=tf.Tensor(shape=(64, 128, 128, 1), dtype=float32)

已做排查:

  • 确认终端与PyCharm使用的解释器完全一致
  • 尝试创建新的conda环境,问题仍未解决
  • 怀疑是PyCharm缓存导致的差异

解决方案

1. 清理PyCharm缓存并重启

  • 点击顶部菜单栏File -> Invalidate Caches...
  • 勾选Clear file system cache and local history,点击Invalidate and Restart
  • 重启后等待PyCharm完成项目索引重建

2. 同步PyCharm的环境变量

  • 打开Run/Debug Configurations(右上角运行按钮旁下拉框选择Edit Configurations)
  • 进入目标运行配置的Environment variables标签页
  • 点击Load environment variables from shell,直接导入终端的环境变量配置
  • 保存配置后重新运行代码

3. 刷新PyCharm的包索引

  • 打开File -> Settings -> Project: [你的项目名] -> Python Interpreter
  • 点击解释器列表旁的刷新图标🔄,等待PyCharm重新扫描已安装包
  • 确认TensorFlow 2.11及cudatoolkit、cudnn等依赖包状态正常

4. 验证GPU设备识别

  • 在代码开头添加以下片段,分别在终端和PyCharm中运行,对比输出:
import tensorflow as tf
print("Available GPUs:", tf.config.list_physical_devices('GPU'))
  • 如果PyCharm无法识别GPU,检查运行配置中是否添加了CUDA_VISIBLE_DEVICES=0环境变量(GPU编号根据实际情况调整)

5. 通过PyCharm重新安装TensorFlow

  • 在Python Interpreter界面找到TensorFlow,点击减号(-)卸载
  • 点击加号(+)搜索tensorflow==2.11.0并安装
  • 全程通过PyCharm的包管理界面操作,确保PyCharm能正确追踪包的安装路径

内容的提问来源于stack exchange,提问作者Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 22:07:54