Skip to content

pydantic 2.0: BaseSettings has been moved to the pydantic-settings package. #260

@marcodigennaro

Description

@marcodigennaro

There is an incompatibility when using pydantic 2.0

$ python run_abipy.py
Traceback (most recent call last):
  File "/home/mdi0316/WORK_RDAA1800022/STO/run_abipy.py", line 3, in <module>
    from abipy.abilab import abiopen
  File "/home/mdi0316/.local/lib/python3.10/site-packages/abipy/abilab.py", line 32, in <module>
    from abipy.core import restapi
  File "/home/mdi0316/.local/lib/python3.10/site-packages/abipy/core/restapi.py", line 12, in <module>
    from pymatgen.ext.matproj import MPRester, MPRestError
  File "/home/mdi0316/.local/lib/python3.10/site-packages/pymatgen/ext/matproj.py", line 28, in <module>
    from mp_api.client import MPRester as _MPResterNew
  File "/home/mdi0316/.local/lib/python3.10/site-packages/mp_api/client/__init__.py", line 5, in <module>
    from .core import MPRestError
  File "/home/mdi0316/.local/lib/python3.10/site-packages/mp_api/client/core/__init__.py", line 1, in <module>
    from .client import BaseRester, MPRestError
  File "/home/mdi0316/.local/lib/python3.10/site-packages/mp_api/client/core/client.py", line 20, in <module>
    from emmet.core.utils import jsanitize
  File "/home/mdi0316/.local/lib/python3.10/site-packages/emmet/core/utils.py", line 25, in <module>
    from emmet.core.settings import EmmetSettings
  File "/home/mdi0316/.local/lib/python3.10/site-packages/emmet/core/settings.py", line 12, in <module>
    from pydantic import BaseSettings, Field, root_validator
  File "/home/mdi0316/.local/lib/python3.10/site-packages/pydantic/__init__.py", line 206, in __getattr__
    return _getattr_migration(attr_name)
  File "/home/mdi0316/.local/lib/python3.10/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/migration/#basesettings-has-moved-to-pydantic-settings for more details.

For further information visit https://errors.pydantic.dev/2.0/u/import-error
$ pip freeze | grep pydantic
pydantic==2.0
pydantic_core==2.0.1
$ conda list | grep pydantic
pydantic                  2.0             py310h2372a71_0    conda-forge
pydantic-core             2.0.1           py310hcb5633a_0    conda-forge

The issue was solved by using a lower version:
$ pip uninstall pydantic
$ pip uninstall pydantic_core
$ conda remove pydantic
$ conda install -c conda-forge pydantic==1.10
$ abirun.py events --help

usage: abirun.py [flowdir] events [-h] [-v] [--no-colors] [--no-logo] [--loglevel LOGLEVEL] [--remove-lock]
                                  [-n NIDS | -w WSLICE | -S TASK_STATUS | -t TASK_CLASS]

options:
  -h, --help            show this help message and exit
  -v, --verbose         verbose, can be supplied multiple times to increase verbosity.
  --no-colors           Disable ASCII colors.
  --no-logo             Disable AbiPy logo.
  --loglevel LOGLEVEL   Set the loglevel. Possible values: CRITICAL, ERROR (default), WARNING, INFO, DEBUG.
  --remove-lock         Remove the lock on the pickle file used to save the status of the flow.
  -n NIDS, --nids NIDS  Node identifier(s) used to select the task. Accept single integer, comma-separated
                        list of integers or python slice. Use `status` command to get the node ids. Examples:
                        --nids=12 --nids=12,13,16 --nids=10:12 to select 10 and 11 (slice syntax),
                        --nids=2:5:2 to select 2,4.
  -w WSLICE, --wslice WSLICE
                        Select the list of works to analyze (python syntax for slices): Examples: --wslice=1
                        to select the second workflow, --wslice=:3 for 0,1,2, --wslice=-1 for the last
                        workflow, --wslice::2 for even indices.
  -S TASK_STATUS, --task-status TASK_STATUS
                        Select only the tasks with the given status. Default: None i.e. ignored. Possible
                        values: ['Initialized', 'Locked', 'Ready', 'Submitted', 'Running', 'Done',
                        'AbiCritical', 'QCritical', 'Unconverged', 'Error', 'Completed'].
  -t TASK_CLASS, --task-class TASK_CLASS
                        Select only tasks with the given class e.g. `-t NscfTask`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions