Snowflake Connector ModuleNotFound only on Streamlit app

I’m trying to connect to our snowflake instance and print rows from a table in Streamlit. When I run the code locally the query executes and I can view the results in rows. However, the main Streamlit window shows a ModuleNotFoundError.

import streamlit as st
import snowflake.connector

Initialize connection.

Uses st.experimental_singleton to only run once.

def init_connection():
return snowflake.connector.connect(user = “XXX”,
account = “XXX”,
warehouse = “XXX”,
database = “XXX”,
schema = “XXX”)

conn = init_connection()

Perform query.

Uses st.experimental_memo to only rerun when the query changes or after 10 min.

def run_query(query):
with conn.cursor() as cur:
return cur.fetchall()

rows = run_query(“SELECT * from XXX;”)

Print results.

for row in rows:
st.write(f"{row[0]} has a :{row[1]}:")

Hi @jcscheide,

Thanks for posting!

Have you added “snowflake-connector-python” to your requirements.txt file?

Caroline :balloon:

Hi @Caroline, I was able to troubleshoot a tricky error!

In the virtual environment that streamlit was running in, I had installed both snowflake-connector-python and a package called snowflake. These two packages don’t work together (I don’t actually know what the snowflake package does), so uninstalling the snowflake package made snowflake-connector-python work!


Glad you figured out the solution, @jcscheide. In case you intend to deploy your app on Streamlit Community Cloud, here’s how you can install the connector on Cloud: Connect Streamlit to Snowflake - Streamlit Docs