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

Pylance提示import "streamlit_webrtc"无法解析,Streamlit运行遇阻求助

streamlit_webrtc组件启动报错,常规重装无法解决

问题复现

执行streamlit run app.py启动Streamlit服务器时,Streamlit本体运行正常,但streamlit_webrtc组件报错,已尝试卸载重装Python、重新安装streamlit及streamlit-webrtc、搭建虚拟环境并更换多款IDE,问题仍未解决。

可行排查/解决步骤

  • 确认Python版本兼容性:streamlit-webrtc仅支持Python 3.8~3.11版本,执行python --version检查版本是否在范围内,不在则更换对应版本。
  • 安装指定稳定版本的streamlit-webrtc:最新版本可能存在兼容bug,尝试安装经过验证的稳定版:
    pip install streamlit-webrtc==0.45.0
    
  • 手动修复依赖库:streamlit-webrtc依赖aiortc、pyav等库,版本不匹配会导致报错,强制安装兼容版本:
    pip install aiortc==1.4.0 pyav==10.0.0
    
  • 清理缓存后彻底重装:清理pip缓存避免残留旧版本文件,再重新安装相关库:
    pip cache purge
    pip uninstall -y streamlit streamlit-webrtc aiortc pyav
    pip install streamlit streamlit-webrtc
    
  • 补充系统级依赖(Linux/macOS):
    • Ubuntu/Debian系统:
      sudo apt-get install libavdevice-dev libavfilter-dev libopus-dev libvpx-dev
      
    • macOS系统(需先安装Homebrew):
      brew install ffmpeg opus libvpx
      
  • 验证最小示例:创建极简测试脚本test_webrtc.py,排除业务代码干扰:
    import streamlit as st
    from streamlit_webrtc import webrtc_streamer
    
    webrtc_streamer(key="test")
    
    执行streamlit run test_webrtc.py,若仍报错则聚焦组件与环境兼容问题,否则排查业务代码中的冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 03:50:21