String url calls sqlalchemy and sqlalchemy calls for psycopg2

This code:

import pandas as pd
import as px
import streamlit as st

def get_data():
df = pd.read_sql(‘diesel-price-by-regions’, ‘string-LINK-to-cloud-POSTGRES’)
return df

df = get_data()

#prepare thr chart
fig = px.line(df, x=‘date’, y=‘diesel_price’, color=‘region’,
title=‘Diesel price in the US’,
‘diesel_price’:‘Price ($)’, ‘region’:‘Region’})




File “/home/appuser/venv/lib/python3.10/site-packages/sqlalchemy/engine/”, line 548, in create_engine
dbapi = dialect_cls.dbapi(**dbapi_args)
File “/home/appuser/venv/lib/python3.10/site-packages/sqlalchemy/dialects/postgresql/”, line 811, in dbapi
import psycopg2
ModuleNotFoundError: No module named ‘psycopg2’

I saw many topics about the same issue but did understand the way to pull data from the cloud postgress without psycopg2.

How to deal with it?

Edit: disregard, I just realized you are talking about the cloud deployment.

Do you have psycopg2 in your requirements.txt?

Even though you’re not using psycopg2 explicitly, that’s what pandas uses under the hood for reading from a postgres db.

no, it is not there. And it is my problem to understand how to overcome this.
I solved the problem by transferring the service to Dash.

If you add the line psycopg2 to a file called requirements.txt, it will automatically install that when you deploy to Streamlit Cloud.

I tried and it seems like Streamlit Cloud rejects any calls related to activities related to hosting DBs.

It does not – we regularly use Streamlit Cloud to read from a wide variety of databases. Could you try following this tutorial here? Connect Streamlit to PostgreSQL - Streamlit Docs

huh, somehow I missed this part of the tutorial. Thanks. I’l play with it when I need quick release to the web