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

Streamlit中TensorFlow ModuleNotFoundError错误的解决方法咨询

修复Streamlit中TensorFlow导入失败的ModuleNotFoundError
  • 添加/更新requirements.txt文件
    在项目根目录创建或编辑requirements.txt,写入TensorFlow和Streamlit的依赖声明,示例:

    tensorflow>=2.15.0
    streamlit>=1.30.0
    

    本地运行的话,执行pip install -r requirements.txt安装依赖;Streamlit Cloud部署时会自动读取该文件安装所需包。

  • 验证Python版本兼容性
    确保安装的TensorFlow版本与当前Python版本匹配,比如你环境是Python 3.9,TensorFlow 2.10-2.15版本都支持这个Python版本,避免安装不兼容的版本导致失败。

  • 本地先测试运行
    在本地项目的虚拟环境中手动安装TensorFlow,执行pip install tensorflow,然后启动Streamlit应用streamlit run streamlit.py,确认本地能正常运行后再部署到云端,排除本地依赖问题。

  • 云端强制重建应用
    如果是Streamlit Cloud上的问题,进入应用的「Manage app」界面,到「Settings」->「Advanced」选项卡,点击「Rebuild this app」,强制重新安装所有依赖包,解决缓存导致的依赖缺失问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 01:33:13