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

如何修复Mac终端/Jupyter运行Gradio界面的AttributeError错误?

解决Gradio 'Interface' 模块属性错误(循环导入导致)

错误原因分析

你遇到的AttributeError: partially initialized module 'gradio' has no attribute 'Interface'(疑似循环导入),常见触发场景包括:脚本与库同名、依赖版本冲突、虚拟环境配置错误。

具体解决步骤

  • 检查脚本命名
    确保你的Python脚本文件名不是gradio.py,当前工作目录下也没有名为gradio的文件夹。如果存在,立即重命名脚本或删除同名文件夹——Python会优先导入本地同名文件/目录,而非官方Gradio库。

  • 重装/升级Gradio
    先清理现有安装:

    pip uninstall -y gradio
    

    安装稳定兼容版本(推荐3.x系列):

    pip install gradio==3.44.0
    

    或直接升级至最新稳定版:

    pip install --upgrade gradio
    
  • 校验虚拟环境(若使用)
    确保激活了正确的虚拟环境,且该环境下已安装所有依赖(Gradio、gpt_index、langchain等)。避免全局环境与虚拟环境的依赖包冲突。

  • 验证Gradio基础功能
    在终端单独运行以下代码,确认Gradio本身可正常使用:

    import gradio as gr
    print(f"Gradio版本: {gr.__version__}")
    demo = gr.Interface(fn=lambda x: x, inputs="text", outputs="text")
    print("Interface初始化成功")
    

代码兼容提示

你的代码中gr.inputs.Textbox属于已弃用语法,建议替换为gr.Textbox(lines=7, label="Enter your text"),避免后续版本兼容问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 08:15:28