streamlit-pydantic
streamlit-pydantic copied to clipboard
Code for simple for throws PydanticImportError
Code for Simple Form in README.md cannot be run
I was starting out with streamlit-pydantic
and tried to run the code for the simple form given in the README.md
, but I encountered an import error while running the simple example.
2023-07-21 20:33:40.546 Uncaught app exception
Traceback (most recent call last):
File "/Users/ayangangopadhyay/Documents/Projects/Expenditure_Dashboard/.venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
exec(code, module.__dict__)
File "/Users/ayangangopadhyay/Documents/Projects/Expenditure_Dashboard/simple_form.py", line 4, in <module>
import streamlit_pydantic as sp
File "/Users/ayangangopadhyay/Documents/Projects/Expenditure_Dashboard/.venv/lib/python3.10/site-packages/streamlit_pydantic/__init__.py", line 9, in <module>
from .settings import StreamlitSettings
File "/Users/ayangangopadhyay/Documents/Projects/Expenditure_Dashboard/.venv/lib/python3.10/site-packages/streamlit_pydantic/settings.py", line 4, in <module>
from pydantic import BaseSettings
File "/Users/ayangangopadhyay/Documents/Projects/Expenditure_Dashboard/.venv/lib/python3.10/site-packages/pydantic/__init__.py", line 207, in __getattr__
return _getattr_migration(attr_name)
File "/Users/ayangangopadhyay/Documents/Projects/Expenditure_Dashboard/.venv/lib/python3.10/site-packages/pydantic/_migration.py", line 288, in wrapper
raise PydanticImportError(
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.0.3/migration/#basesettings-has-moved-to-pydantic-settings for more details.
For further information visit https://errors.pydantic.dev/2.0.3/u/import-error
The code I am trying to run is exactly the one given for the simple form -
import streamlit as st
from pydantic import BaseModel
import streamlit_pydantic as sp
class ExampleModel(BaseModel):
some_text: str
some_number: int
some_boolean: bool
data = sp.pydantic_form(key="my_form", model=ExampleModel)
if data:
st.json(data.json())
Expected behaviour:
Rendering a simple form with streamlit-pydantic
.
Steps to reproduce the issue:
- Create a
.venv
- Install required dependencies
- Create the
simple_form.py
file using the above code or copying it from theREADME.md
-
streamlit run simple_form.py
-->
Technical details:
- Host Machine OS (Windows/Linux/Mac): Mac
- Browser (Chrome/Firefox/Safari): Arc/Mozilla
- Python Version: 3.10.8
- streamlit-pydantic Version: 0.6.0
- streamlit: 1.24.1
Please let me know if any further details are required, and I will be happy to provide them. Thanks!
@SnoozingSimian
Fixed here: #35. Not yet released.
Short term work around - downgrade to pydantic 1.10.11.
Duplicate of #33
I had the same problem. I fixed through the following steps: (If you like to align with the pydantic 2.4.2.) First, install the following package:
pip install pydantic-settings
change the line 4 from:
from pydantic import BaseSettings
to the following:
from pydantic_settings import BaseSettings
That will fix the problem for you. With that being said, there might be additional misalignment problems elsewhere. Hence it might be a better choice to use the official solutions.
@SnoozingSimian
Fixed here: #35. Not yet released.
Short term work around - downgrade to pydantic 1.10.11.
@frederickmannings when will this be released? This project looks promising, but given that the rest of my system uses pydantic > 2, this is a blocker.
Any update on a release with an official fix? The import error is still present with the current release on pypi.