Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for simple for throws PydanticImportError #38

Open
SnoozingSimian opened this issue Jul 21, 2023 · 6 comments
Open

Code for simple for throws PydanticImportError #38

SnoozingSimian opened this issue Jul 21, 2023 · 6 comments
Labels
type:bug Something isn't working

Comments

@SnoozingSimian
Copy link

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:

  1. Create a .venv
  2. Install required dependencies
  3. Create the simple_form.py file using the above code or copying it from the README.md
  4. 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 SnoozingSimian added the type:bug Something isn't working label Jul 21, 2023
@frederickmannings
Copy link

frederickmannings commented Jul 23, 2023

@SnoozingSimian

Fixed here: #35. Not yet released.

Short term work around - downgrade to pydantic 1.10.11.

@szabi
Copy link
Contributor

szabi commented Aug 2, 2023

Duplicate of #33

@shengxio
Copy link

shengxio commented Oct 24, 2023

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.

@tamir-alltrue-ai
Copy link

@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.

@aryan-jain
Copy link

Any update on a release with an official fix? The import error is still present with the current release on pypi.

@tomliptrot
Copy link

Hi, I'm still getting this error using v 0.6.0 on pypi, this PR (#35) seems to fix it, but its not fixed in the version I am using. Any idea why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants