Issues with altair and imghdr packages

Hello,

I am having an issue that has been posted about in the forum but the solution didn’t work for me. My app was working fine when all of a sudden I get the error at deployment:

ModuleNotFoundError: No module named 'altair.vegalite.v4'

When I tried the solution proposed under this post ModuleNotFoundError: No module named 'altair.vegalite.v4' , I get yet another issue:

ModuleNotFoundError: No module named 'imghdr'

It may be something related to streamlit cloud over which I have no much control. Feedback would be appreciated and thanks!

PS: My app runs fine locally.

Hey there, thanks for reaching out and for checking the forum first! This is a common issue on Streamlit Community Cloud, especially after updates to Altair or Streamlit. The error ModuleNotFoundError: No module named ‘altair.vegalite.v4’ usually means your app is using an older version of Streamlit that expects Altair v4, but a newer Altair (v5+) is being installed by default. The recommended fix is to pin Altair to a version below 5 in your requirements.txt (add altair<5), or upgrade Streamlit to >=1.20.0, which supports Altair v5. After updating, reboot your app to apply the changes. For more, see the official guidance and forum discussions.

The imghdr error is unrelated to Altair and is likely due to Python 3.13, where the imghdr module was removed from the standard library. If your app or a dependency uses imghdr, you’ll need to either downgrade to Python 3.12 (set python-3.12 in runtime.txt) or add imghdr as a third-party package if available. Make sure your requirements.txt and runtime.txt are in the root of your repo, and reboot after changes. If you’re still stuck, please share your requirements.txt and runtime.txt, and encourage others to jump in with their insights!

Sources: