No module named 'sqlalchemy' with deployed app

My Public Streamlit Cloud App can be seen here:
https://orderdash.streamlit.app/

My GitHub page for the app can be seen here:

I deployed a streamlit app on the community cloud using GitHub - streamlit/app-starter-kit: Streamlit App Starter Kit helps kick start your Streamlit app creation., then followed the guide in Connect Streamlit to PostgreSQL<!-- --> - Streamlit Docs to connect to a database. I have filled in secrets, as well as adding psycopg2-binary and
sqlalchemy to the requirements file. However, the st.connect function always causes ModuleNotFound. I have tried both unpinned and pinned versions in the requirements.txt

Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/app-starter-kit/streamlit_app.py", line 6, in <module>
    conn = st.connection("postgresql", type="sql")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/connection_factory.py", line 343, in connection_factory
    raise ModuleNotFoundError(f"{str(e)}. {extra_info}")
ModuleNotFoundError: No module named 'sqlalchemy'. You need to install the 'sqlalchemy' package to use this connection.

The requirements.txt file content in your github repo is not correct.

You need to add the following.

# requirements.txt
psycopg2-binary==x.x.x
sqlalchemy==x.x.x

That is the recommended libraries to connect to postgresql.

Sorry, I don’t quite understand. I have these two libraries in my requirements.txt as shown below:
streamlit
psycopg2-binary
sqlalchemy==2.0.22

Ahh misunderstanding.

Can you make it clear where is your github repo that you use?

Got it, I labeled it and moved it up

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.