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

VSCode运行Streamlit报错:module 'streamlit' has no attribute 'title'

问题排查:Streamlit title属性不存在及CLI命令报错

问题场景

我正在创建一个新的Streamlit应用,代码如下:

import streamlit as st
st.title("Grid Generator")

导入streamlit模块无报错,但执行第二行时出现错误:

AttributeError: module 'streamlit' has no attribute 'title'

已确认使用VSCode的正确Python环境,卸载重装streamlit后显示成功安装streamlit-1.33.0,但执行streamlit version show时出现报错:

Successfully installed streamlit-1.33.0

PS C:\Users\dld\OneDrive - Equinor\python> streamlit version show
Traceback (most recent call last):
      File "<frozen runpy>", line 198, in _run_module_as_main
      File "<frozen runpy>", line 88, in _run_code
      File "C:\Appl\my_env\Scripts\streamlit.exe\__main__.py", line 4, in <module>
    ModuleNotFoundError: No module named 'streamlit.web'; 'streamlit' is not a package

排查与解决步骤

  • 检查项目目录同名文件/文件夹
    项目文件夹里如果存在streamlit.py文件或streamlit文件夹,会优先被Python导入,覆盖官方的Streamlit库,导致无法加载完整包结构。直接删除或重命名这类文件/文件夹即可。

  • 验证Streamlit包完整性
    激活目标Python环境后,打开Python交互终端执行以下命令:

    import streamlit
    print(streamlit.__file__)
    
    • 如果输出路径不是环境site-packages目录下的streamlit文件夹,说明导入了错误模块,排查项目目录的同名文件。
    • 如果路径正确,检查该文件夹下是否存在web子目录和__init__.py文件,缺失则说明安装不完整,执行重装命令:
      pip uninstall -y streamlit
      pip install --no-cache-dir streamlit==1.33.0
      
  • 确认VSCode解释器配置
    查看VSCode右下角显示的Python解释器路径,确认是否和安装streamlit的虚拟环境路径一致。如果不一致,点击路径选择正确环境;运行代码时确保使用该环境的终端,避免全局环境与虚拟环境混淆。

  • 修复CLI脚本
    若上述步骤无效,强制重装Streamlit以修复损坏的CLI入口脚本:

    pip install --force-reinstall streamlit==1.33.0
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 07:30:12