使用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,环境不匹配是核心问题。需:- 选择一个固定环境(如pyenv的3.10.6或anaconda的3.9)
- 在该环境下重新安装所有依赖:
pip install streamlit langchain protobuf - 运行你自己编写的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
相关产品推荐
相关产品推荐

