Encountering ModuleNotFoundError: No module named 'altair.vegalite.v4' when deploying to streamlit cloud

Hey there, thanks for reaching out to the community! :unicorn: This is a common issue when deploying Streamlit apps, especially with the error ModuleNotFoundError: No module named ‘altair.vegalite.v4’. Even if you don’t directly use Altair, Streamlit depends on it for some charting features, and the version compatibility between Streamlit and Altair is crucial.

To fix this, you should explicitly add altair<5 to your requirements.txt file if you’re using a Streamlit version older than 1.20.0. For newer Streamlit versions (1.23.0+), Altair v5 is supported, so you can use a newer Altair version or upgrade Streamlit. After updating requirements.txt, reboot your app. For more details, see the official guidance at the bottom of the Streamlit Community Cloud status page and related forum discussions.

Sources: