完成Snowflake第3枚徽章训练时Streamlit应用报snowflake模块缺失错误
我正在完成Snowflake第3枚徽章的训练,使用Streamlit开发应用。部署到Streamlit Cloud运行时出现错误:
ModuleNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Traceback:
File "/mount/src/melanies_smoothies/streamlit_app.py", line 3, in
from snowflake.snowpark.functions import col
点击「Manage app」后看到详细错误:
ModuleNotFoundError: No module named 'snowflake'
2025-08-11 15:48:47.425 503 GET /script-health-check (127.0.0.1) 180.27ms
我已在GitHub仓库中配置了requirements.txt和environment.yml来关联Snowflake依赖,Streamlit正是从该仓库拉取应用。
我的requirements.txt内容如下:
# requirements.txt snowflake-connector-python snowflake-snowpark-python streamlit==1.31.0 requests
我的environment.yml内容如下:
name: app_environment channels: - snowflake dependencies: - python=3.8.* - snowflake-snowpark-python= - streamlit= - snowflake-sqlalchemy - snowflake-snowpark-python=1.9.0 - snowflake-connector-python=3.11.0
恳请帮忙排查模块缺失的问题。
移除冲突的
environment.yml文件
Streamlit Cloud默认优先使用requirements.txt,但同时存在environment.yml时会尝试用Conda构建环境。你的environment.yml存在重复依赖声明(snowflake-snowpark-python出现两次,其中一次无版本号),会导致Conda环境构建失败,依赖未正确安装。直接删除该文件,让Streamlit使用requirements.txt安装依赖,这是Streamlit Cloud推荐的更可靠方式。明确
requirements.txt中的依赖版本(可选但推荐)
为避免版本兼容问题,建议给Snowflake相关依赖添加明确版本号,和本地开发环境保持一致:# requirements.txt snowflake-connector-python==3.11.0 snowflake-snowpark-python==1.9.0 streamlit==1.31.0 requests触发重新部署
修改文件后推送到GitHub,回到Streamlit Cloud应用页面,点击右上角的「⋮」选择「Redeploy」,确保新的依赖配置被加载。检查文件路径
确认requirements.txt和streamlit_app.py在仓库根目录下,不要放在子文件夹中,否则Streamlit可能无法识别依赖配置。
内容的提问来源于stack exchange,提问作者Azzna

