Colab中通过LocalTunnel运行Streamlit失效问题求助
问题原因与解决方法
问题原因
报错AttributeError: Enum LabelVisibilityOptions has no value defined for name 'ValueType'是Streamlit与Colab预装的protobuf版本不兼容导致的:
- 新版protobuf(3.21及以上)移除了枚举类型的
ValueType属性 - 旧版Streamlit代码中仍依赖该属性,启动时触发错误
- 后续的504网关超时是因为Streamlit服务未成功启动,LocalTunnel无法连接到有效服务
解决步骤
- 卸载冲突的protobuf版本,安装兼容的旧版本
!pip uninstall protobuf -y !pip install protobuf==3.20.3 streamlit -q - 保留原有的
app.py代码不变:%%writefile app.py import streamlit as st st.write('# test') - 重新启动Streamlit与LocalTunnel服务:
!streamlit run /content/app.py & npx localtunnel --port 8501
补充说明
- 如果仍有问题,可以尝试指定明确的Streamlit兼容版本,比如
streamlit==1.19.0,确保和protobuf 3.20.3完全匹配 - 操作完成后,点击LocalTunnel生成的链接,即可正常访问Streamlit应用
内容的提问来源于stack exchange,提问作者Patty
相关产品推荐
相关产品推荐

