我收到 Pydantic 导入错误:即使使用 ydata 分析后,基本设置也已移动

问题描述 投票:0回答:1

这是我的代码。

from ydata_profiling import ProfileReport as pf

这是错误

PydanticImportError                       Traceback (most recent call last)
Cell In[14], line 1
----> 1 from ydata_profiling import ProfileReport as pf

File ~\anaconda3\Lib\site-packages\ydata_profiling\__init__.py:7
      1 """Main module of ydata-profiling.
      2 
      3 .. include:: ../../README.md
      4 """
      5 import importlib.util
----> 7 from ydata_profiling.compare_reports import compare
      8 from ydata_profiling.controller import pandas_decorator
      9 from ydata_profiling.profile_report import ProfileReport

File ~\anaconda3\Lib\site-packages\ydata_profiling\compare_reports.py:9
      6 import pandas as pd
      7 from dacite import from_dict
----> 9 from ydata_profiling.config import Correlation, Settings
     10 from ydata_profiling.model import BaseDescription
     11 from ydata_profiling.model.alerts import Alert

File ~\anaconda3\Lib\site-packages\ydata_profiling\config.py:7
      4 from typing import Any, Dict, List, Optional, Tuple, Union
      6 import yaml
----> 7 from pydantic import BaseModel, BaseSettings, Field, PrivateAttr
     10 def _merge_dictionaries(dict1: dict, dict2: dict) -> dict:
     11     """
     12     Recursive merge dictionaries.
     13 
   (...)
     16     :return: Merged dictionary
     17     """

File ~\anaconda3\Lib\site-packages\pydantic\__init__.py:210, in __getattr__(attr_name)
    208 dynamic_attr = _dynamic_imports.get(attr_name)
    209 if dynamic_attr is None:
--> 210     return _getattr_migration(attr_name)
    212 from importlib import import_module
    214 module = import_module(_dynamic_imports[attr_name], package=__package__)

File ~\anaconda3\Lib\site-packages\pydantic\_migration.py:289, in getattr_migration.<locals>.wrapper(name)
    287     return import_string(REDIRECT_TO_V1[import_path])
    288 if import_path == 'pydantic:BaseSettings':
--> 289     raise PydanticImportError(
    290         '`BaseSettings` has been moved to the `pydantic-settings` package. '
    291         f'See https://docs.pydantic.dev/{version_short()}/migration/#basesettings-has-moved-to-pydantic-settings '
    292         'for more details.'
    293     )
    294 if import_path in REMOVED_IN_V2:
    295     raise PydanticImportError(f'`{import_path}` has been removed in V2.')

PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.3/migration/#basesettings-has-moved-to-pydantic-settings for more details.

For further information visit https://errors.pydantic.dev/2.3/u/import-error

我唯一尝试的就是导入 ydata-profiling 库。我希望这个库能够通过使用 ydata-profiling 来工作,因为 Pandas-profiling 已经过时,并且 Pydantic 已经推出了其版本 2。 我正在尝试对其进行探索性数据分析(EDA)。

python pandas importerror pydantic
1个回答
0
投票

您的 ydata_profiling 版本仅适用于较旧的 pydantic 版本。从堆栈跟踪中的链接: https://docs.pydantic.dev/2.3/errors/usage_errors/#import-error

当您尝试导入曾经存在的对象时,会引发此错误 在 Pydantic V1 中可用,但在 Pydantic V2 中已被删除。

请参阅迁移指南了解更多信息。

如果将 ydata_profiling 升级到最新版本无法修复问题,则需要降级 pydantic-version。如果你的代码库中需要这样的技巧,我强烈建议使用

venv
来管理你的 python 包。

© www.soinside.com 2019 - 2024. All rights reserved.