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

PydanticImportError: BaseSettings has been moved to the pydantic-settings package #457

Closed
dillfrescott opened this issue Jul 9, 2023 · 17 comments
Labels
bug Something isn't working

Comments

@dillfrescott
Copy link

Traceback (most recent call last):
  File "C:\Users\micro\miniconda3\envs\test\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\micro\miniconda3\envs\test\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\micro\miniconda3\envs\test\lib\site-packages\llama_cpp\server\__main__.py", line 29, in <module>
    from llama_cpp.server.app import create_app, Settings
  File "C:\Users\micro\miniconda3\envs\test\lib\site-packages\llama_cpp\server\app.py", line 15, in <module>
    from pydantic import BaseModel, BaseSettings, Field, create_model_from_typeddict
  File "C:\Users\micro\miniconda3\envs\test\lib\site-packages\pydantic\__init__.py", line 206, in __getattr__
    return _getattr_migration(attr_name)
  File "C:\Users\micro\miniconda3\envs\test\lib\site-packages\pydantic\_migration.py", line 279, in wrapper
    raise PydanticImportError(
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.0.2/migration/#basesettings-has-moved-to-pydantic-settings for more details.

For further information visit https://errors.pydantic.dev/2.0.2/u/import-error
@IgnacioFDM
Copy link

Same, solved it downgrading pydantic
pip install pydantic==1.10.11

@dillfrescott
Copy link
Author

Oh. Thank you for the info!

@AbhinasRegmi
Copy link

AbhinasRegmi commented Jul 9, 2023

In the pydantic v2 the BaseSettings has been moved to a different package. First install pydantic-settings by
pip install pydantic-settings
and replace
from pydantic import BaseSettings
with
from pydantic_settings import BaseSettings

It should work after that.

@Calandiel
Copy link

Glad to see it's nothing more complex but this really ought to be fixed on the repo

@gjmulder gjmulder changed the title Error PydanticImportError: BaseSettings has been moved to the pydantic-settings package Jul 9, 2023
@gjmulder gjmulder added the bug Something isn't working label Jul 9, 2023
@Calandiel
Copy link

There's some additional issues related to this as far as I can tell -- type no longer exists on FieldInfo (seems to be called annotation now?) which makes the server fail.

@abetlen
Copy link
Owner

abetlen commented Jul 9, 2023

@dillfrescott was this on a pip install or via git?

FastAPI recently upgraded to pydantic v2 which should be much faster however it does introduce some breaking changes. Can you try upgrading to the new v0.1.69 version I just published?

@uogbuji
Copy link

uogbuji commented Jul 9, 2023

@abetlen On v0.1.69 I got past the OP issue with pip install -U pydantic pydantic-settings fastapi but I'm now running into a related error:

.local/venv/llmhost/lib/python3.11/site-packages/pydantic/_internal/_fields.py:126: UserWarning: Field "model_alias" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ('settings_',)`.
  warnings.warn(
/Users/uche/.local/venv/llmhost/lib/python3.11/site-packages/pydantic/_internal/_config.py:261: UserWarning: Valid config keys have changed in V2:
* 'schema_extra' has been renamed to 'json_schema_extra'
  warnings.warn(message, UserWarning)
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/uche/.local/venv/llmhost/lib/python3.11/site-packages/llama_cpp/server/__main__.py", line 33, in <module>
    for name, field in Settings.__model_fields__.items():
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/uche/.local/venv/llmhost/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 193, in __getattr__
    raise AttributeError(item)
AttributeError: __model_fields__. Did you mean: 'model_fields'?

@uogbuji
Copy link

uogbuji commented Jul 10, 2023

@abetlen On v0.1.69 I got past the OP issue with pip install -U pydantic pydantic-settings fastapi but I'm now running into a related error:

AttributeError: __model_fields__. Did you mean: 'model_fields'?

FYI the 0.1.70 release fixed this error.

@Alberoyang
Copy link

Alberoyang commented Jul 10, 2023

Hi~ sames as me.
截屏2023-07-10 17 55 29
And if I set pydantic to 1.10.11, will be
image
I can't satisfy all.

@snxraven
Copy link

I am also seeing this issue within my docker builds, not sure how to fix it, I am seeing it on all recent versions

@snxraven
Copy link

Latest release 0.1.71 fixed this issue for me.

@amj
Copy link

amj commented Jul 19, 2023

not currently working on 0.1.73

@larrycai
Copy link

larrycai commented Oct 14, 2023

pip install pydantic==1.10.11

now llama_cpp_python is 0.2.11, this change doesn't work

ModuleNotFoundError: No module named 'pydantic._internal'

@abetlen abetlen closed this as completed Feb 26, 2024
@DLesmes
Copy link

DLesmes commented Apr 10, 2024

it is not resolved, why did you close it @abetlen

despite to do this:
pip install pydantic-settings

and run this:
from pydantic_settings import BaseSettings

it doesn’t work for many libraries and it's dependencies 🐍

@Srajangpt1
Copy link

I am running into similar error

@abetlen
Copy link
Owner

abetlen commented Apr 14, 2024

@DLesmes it should be resolved with the pydantic-settings dependency in pyproject.toml. If you run try python3 -m pip install pydantic-settings then python3 -c "from pydantic_settings import BaseSettings" does that still cause issues? It may be a mismatch between your pip and python intepreter.

@aguennoune
Copy link

pip install pydantic==1.10.11
It works! streamlit_pydantic won't work without this pydantic version downgrade

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

No branches or pull requests