Streamlit Cloud部署时requirements.txt报错求助
Streamlit Cloud部署requirements.txt问题解决
问题根源
错误日志明确指向pytest==2.0.0的安装失败:这个超旧版本的pytest在安装流程中会尝试通过HTTP协议下载依赖包,而当前PyPI已强制要求使用HTTPS协议,因此触发403权限错误。
解决方案
处理pytest依赖
- 若你的Streamlit应用无需pytest作为运行时依赖,直接从requirements.txt中删除
pytest==2.0.0 - 若需要pytest,将版本替换为兼容HTTPS的新版本,例如
pytest==7.4.0(选择稳定的较新版本即可)
- 若你的Streamlit应用无需pytest作为运行时依赖,直接从requirements.txt中删除
清理冗余依赖
你的requirements.txt包含大量本地开发或Windows专属包,Streamlit Cloud基于Linux环境部署,无需这些依赖,建议移除:pywin32==302(Windows专属组件)jupyterlab==2.2.6(本地开发工具)wincertstore==0.2(Windows证书管理工具)- 其他非应用运行必需的开发类依赖也可酌情删除
优化后的requirements.txt示例
altair==4.2.0 blinker==1.5 chart-studio==1.1.0 commonmark==0.9.1 et-xmlfile==1.1.0 gitdb==4.0.9 GitPython==3.1.29 llvmlite==0.39.1 mistune==0.8.4 munch==2.5.0 openpyxl==3.0.10 patsy==0.5.2 Pillow==9.0.1 plotly==4.14.1 protobuf==3.16.0 pyarrow==10.0.0 pyasn1==0.4.8 pyasn1-modules==0.2.7 pydeck==0.8.0 pyproj==3.3.1 pytz==2021.3 pytz-deprecation-shim==0.1.0.post0 PyYAML==6.0 rich==12.6.0 scikit-plot==0.3.7 semver==2.13.0 Shapely==1.8.2 smmap==5.0.0 statsmodels==0.12.1 streamlit==1.14.0 toolz==0.12.0 tzdata==2022.6 tzlocal==4.2 Unidecode==1.1.1 validators==0.20.0 watchdog==2.1.9 xgboost==1.7.1 setuptools==65.5.0
额外提示
- Streamlit Cloud会自动完成pip版本升级,无需手动执行升级命令
- 部署时仅保留应用运行必需的依赖,可减少安装时间和版本冲突概率
内容的提问来源于stack exchange,提问作者This_is_S
相关产品推荐
相关产品推荐

