whitphx / stlite

In-browser Streamlit 🎈🚀
https://edit.share.stlite.net
Apache License 2.0
1.25k stars 65 forks source link

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

Closed colasajee closed 1 year ago

colasajee commented 1 year ago

Get this error everytime with all stlite webapps. Even when trying the stlite demo examples.

Seems to be an issue with Streamlit not being compatible with the recently released altair==5.0 I believe Stlite is loading the latest version of altair by default where as Streamlit supports altair version 4 and below hence the issue. Please see the Traceback below.

Traceback (most recent call last): File "/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception File "/lib/python3.10/asyncio/tasks.py", line 232, in __step result = coro.send(None) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 506, in eval_code_async await CodeRunner( File "/lib/python3.10/site-packages/_pyodide/_base.py", line 357, in run_async coroutine = eval(self.code, globals, locals) File "", line 2, in File "/lib/python3.10/site-packages/streamlit/init.py", line 55, in from streamlit.delta_generator import DeltaGenerator as _DeltaGenerator File "/lib/python3.10/site-packages/streamlit/delta_generator.py", line 45, in from streamlit.elements.arrow_altair import ArrowAltairMixin File "/lib/python3.10/site-packages/streamlit/elements/arrow_altair.py", line 36, in from altair.vegalite.v4.api import Chart ModuleNotFoundError: No module named 'altair.vegalite.v4'

aggieed97 commented 1 year ago

I started getting the same error the last few days on my app as well. I don't use Altair so was trying to find some other fix for this but have been unsuccessful so far.

colasajee commented 1 year ago

I think stlite loads Altair library by default even where it's not being explicitly imported

aggieed97 commented 1 year ago

FWIW, I updated the following 2 lines of code in my script, and my html/website works now:

href="https://cdn.jsdelivr.net/npm/@stlite/mountable@0.31.0/build/stlite.css"

<script src="https://cdn.jsdelivr.net/npm/@stlite/mountable@0.31.0/build/stlite.js"></script>

My original code was running on 0.26.0 and now is updated to 0.31.0 as seen above.

niuguy commented 1 year ago

@stlite/desktop upgrade to 0.31.0 solved this issue on my end

whitphx commented 1 year ago

Hi, thank you for the report. This is a bug on original Streamlit and streamlit<=1.19.0 has been affected by the release of Altair v5. stlite has upgraded its internal Streamlit version from 1.19.0 to 1.21.0 since 0.31.0, so using this version solves the problem as they reported above.

Another workaround might be to add altair<5 to your requirements.txt, as discussed at https://discuss.streamlit.io/t/modulenotfounderror-no-module-named-altair-vegalite-v4/42921/6, while I'm not sure if it works with @stlite/desktop as well.

colasajee commented 1 year ago

Thank you all. Everything works as expected with stlite 0.31.0

GVanave commented 8 months ago

pip install altair==4 can also solve the same issue