Discovered Streamlit today, going down the Get Started section, but Pandas with styler example does not work.
Steps to reproduce
I am talking about this example:
import streamlit as st
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(
columns=('col %d' % i for i in range(20)))
Expected to see a dataframe in the browser.
Instead, I get: KeyError:‘warnings’
Followed by a long Traceback:
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 564, in _run_script
File "C:\Users\salazag\programs\streamlit\htp3\htp3.py", line 10, in <module>
dataframe = pd.DataFrame(
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\frame.py", line 721, in __init__
mgr = ndarray_to_mgr(
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\internals\construction.py", line 345, in ndarray_to_mgr
index, columns = _get_axes(
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\internals\construction.py", line 753, in _get_axes
columns = ensure_index(columns)
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\indexes\base.py", line 7374, in ensure_index
return Index._with_infer(index_like, copy=copy, tupleize_cols=False)
File "C:\programs\gttools\python3\3.10.5\lib\site-packages\pandas\core\indexes\base.py", line 715, in _with_infer
File "C:\programs\gttools\python3\3.10.5\lib\warnings.py", line 446, in __init__
self._module = sys.modules['warnings'] if module is None else module
- Streamlit version: 1.15.2
- Python version: 3.10.5
- Using Conda? PipEnv? PyEnv? Pex? No. Working locally with Python installations and site-packages.
- OS version: Windows 10, Version 21H2
- Browser version: Edge Version 107
No, working locally with everything already installed.
I copied the code and appended for reference:
st.write('Streamlit ' + st.__version__)
st.write('Pandas ' + pd.__version__)
st.write('Numpy ' + np.__version__)
I ran it in two environments and got:
Can you insert the version checks right after the import lines and see if it can execute that? If so, what versions did you get? If not, can you try a new environment or maybe try reinstalling the modules?
I guess this may be a problem with the Python distro that I am using?
Yeah, seems like something. Looks like Streamlit is running fine with the simple write version commands and you’ve got the same combo as one of the environments I used. Can you spin up a clean environment to try? Or since the errors seem to be in pandas, you might try reinstalling that module.
((Are you familiar with using environments to make it easy to play around with different module versions? I’m on my tablet, but can pop over to desktop to grab a few easy directions. Do you just have Python installed directly? Do you have Anaconda? I like Anaconda for easy environment management.))
Yes, I know my way around environments. So, let me start anew; maybe something happened after I installed one too many web frameworks…I have been reading up online and experimenting with flet, flask, nicegui, web2py, streamlit…looking for the one I would like.
Were you able to run the code in a clean environment?
As for which is best, I think it highly depends on your use case/skills. One of Streamlit’s strong points is that you get to an operable dashboard with very little code and that it’s probably one of the most beginner friendly options.
However, if your goal is a broader, more generic web framework, you’ll probably feel constrained in Streamlit.
This web stuff is all new to me, but, apparently, the direction new management wants to go; so, here I am.
I am an engineer and work for an engineering department, but moved to the software side of things some years ago. Given that the know-how is proprietary and very technical, most in-house software is written by engineers with little software knowledge and even less interest in developing such skill…this is one reason why I typically prefer/search easy-to-use options.
So, I started with a clean Python installation and “only” installed streamlit…the example now works.
Thanks for your assistance and feedback.
No problem. Sounds like Streamlit is a great option for you to explore, then.