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

使用Streamlit+LangChain搭建在线AutoGPT应用时遇ImportError求助

问题:LangChain+Streamlit搭建AutoGPT应用时的protobuf导入错误

我在尝试使用LangChain与Streamlit搭建在线AutoGPT应用时遇到如下错误:

终端执行的命令:

streamlit run /Users/*username*/opt/anaconda3/lib/python3.9/site-packages/ipykernel_launcher.py

返回的报错信息:

Traceback (most recent call last):
  File "/Users/*username*/.pyenv/versions/3.10.6/bin/streamlit", line 5, in <module>
    from streamlit.web.cli import main
  File "/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/streamlit/__init__.py", line 55, in <module>
    from streamlit.delta_generator import DeltaGenerator as _DeltaGenerator
  File "/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/streamlit/delta_generator.py", line 36, in <module>
    from streamlit import config, cursor, env_util, logger, runtime, type_util, util
  File "/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/streamlit/cursor.py", line 18, in <module>
    from streamlit.runtime.scriptrunner import get_script_run_ctx
  File "/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/streamlit/runtime/__init__.py", line 16, in <module>
    from streamlit.runtime.runtime import Runtime as Runtime
  File "/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/streamlit/runtime/runtime.py", line 29, in <module>
    from streamlit.proto.BackMsg_pb2 import BackMsg
  File "/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/streamlit/proto/BackMsg_pb2.py", line 5, in <module>
    from google.protobuf import descriptor as _descriptor
  File "/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 47, in <module>
    from google.protobuf.pyext import _message
ImportError: dlopen(/Users/*username*/.pyenv/versions/3.10.6/lib/python3.10/site-packages/google/protobuf/pyext/_message.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '__ZN6google8protobuf15FieldDescriptor12TypeOnceInitEPKS1_'
解决方向
  • 统一Python运行环境:当前命令同时调用了pyenv的Python3.10.6环境(streamlit所在)和anaconda3的Python3.9路径下的ipykernel_launcher.py,环境不匹配是核心问题。需:

    1. 选择一个固定环境(如pyenv的3.10.6或anaconda的3.9)
    2. 在该环境下重新安装所有依赖:pip install streamlit langchain protobuf
    3. 运行你自己编写的Streamlit脚本,而非ipykernel_launcher.py(这是Jupyter的启动文件,不能直接作为Streamlit入口)
  • 重装protobuf依赖:报错源于protobuf的C扩展库符号缺失,执行以下命令重装:

    pip uninstall -y protobuf
    pip install protobuf==4.24.4  # 该版本与多数Streamlit版本兼容,可按需调整
    
  • 清理缓存后重装所有依赖:若重装protobuf无效,清理pip缓存后重新安装全套依赖:

    pip cache purge
    pip install --no-cache-dir streamlit langchain protobuf
    
  • 验证环境一致性:运行which python和which streamlit,确保输出路径属于同一个Python环境,避免跨环境调用导致的依赖混乱。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 21:07:35