Skip to content

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

Closed
@dillfrescott

Description

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

Activity

IgnacioFDM

IgnacioFDM commented on Jul 9, 2023

@IgnacioFDM

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

dillfrescott

dillfrescott commented on Jul 9, 2023

@dillfrescott
Author

Oh. Thank you for the info!

AbhinasRegmi

AbhinasRegmi commented on Jul 9, 2023

@AbhinasRegmi

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

Calandiel commented on Jul 9, 2023

@Calandiel

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

changed the title [-]Error[/-] [+]PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package[/+] on Jul 9, 2023
Calandiel

Calandiel commented on Jul 9, 2023

@Calandiel

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

abetlen commented on Jul 9, 2023

@abetlen
Owner

@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

uogbuji commented on Jul 9, 2023

@uogbuji

@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

uogbuji commented on Jul 10, 2023

@uogbuji

@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

Alberoyang commented on Jul 10, 2023

@Alberoyang

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

snxraven commented on Jul 10, 2023

@snxraven

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

snxraven commented on Jul 14, 2023

@snxraven

Latest release 0.1.71 fixed this issue for me.

amj

amj commented on Jul 19, 2023

@amj

not currently working on 0.1.73

larrycai

larrycai commented on Oct 14, 2023

@larrycai

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'

DLesmes

DLesmes commented on Apr 10, 2024

@DLesmes

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

Srajangpt1 commented on Apr 13, 2024

@Srajangpt1

I am running into similar error

abetlen

abetlen commented on Apr 14, 2024

@abetlen
Owner

@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

aguennoune commented on Jun 1, 2024

@aguennoune

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

Harshad046

Harshad046 commented on Jul 11, 2024

@Harshad046

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.

I used your solution but I am still getting the same message as I am trying to use pandas_profiling or streamlit_pandas_profiling, can you help with the fix ?

medsouza

medsouza commented on Jul 27, 2024

@medsouza

@Harshad046, pandas_profiling has been deprecated. Use ydata_profiling instead. Uninstall everything and follow the instructions in the link below:
https://github.com/ydataai/ydata-profiling

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @larrycai@uogbuji@amj@snxraven@abetlen

        Issue actions

          PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package · Issue #457 · abetlen/llama-cpp-python