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

导入keras_hub时触发_pywrap_tensorflow_internal的DLL加载失败错误

问题描述

执行以下代码时触发ImportError:

import keras_hub

报错来自pywrap_tensorflow.py中的这段代码块:

try:
    from tensorflow.python._pywrap_tensorflow_internal import *
except ModuleNotFoundError:
    pass

具体报错信息:

from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal

当前环境:

  • TensorFlow 2.19.0
  • Keras-Hub 0.20.0(也曾尝试0.19.0)
  • 已安装.NET和MV C++ Redistributable 2015-2022
  • CPU:Intel(R) Core(TM) i9-12900K
  • 已尝试常规Stack Overflow方案但未解决
排查与修复方案
  • 确认Python版本兼容性:TensorFlow 2.19.0要求Python版本在3.9-3.12区间,版本不匹配会直接导致底层DLL加载失败。
  • 重装TensorFlow与Keras-Hub:
    1. 卸载现有包:
      pip uninstall -y tensorflow keras-hub
      
    2. 清空pip缓存:
      pip cache purge
      
    3. 重新安装指定版本:
      pip install tensorflow==2.19.0 keras-hub==0.20.0
      
  • 安装CPU优化版TensorFlow:针对Intel 12代CPU,尝试安装官方优化的CPU版本:
    pip install tensorflow-intel==2.19.0
    
  • 修复系统依赖:
    1. 卸载现有MV C++ Redistributable 2015-2022,重新下载对应x64架构的最新版本安装,确保安装过程无报错。
    2. 把Python安装路径下的Lib\site-packages\tensorflow\core目录添加到系统环境变量PATH中,重启终端后再测试。
  • 单独验证TensorFlow:先测试TensorFlow基础导入是否正常,再排查Keras-Hub:
    import tensorflow as tf
    print(tf.__version__)
    print(tf.test.is_built_with_cuda())
    
    如果单独导入TensorFlow就报错,说明问题根源在TensorFlow本身。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 13:12:05