在Jupyter Notebook中运行ydata_profiling代码时出现No module named 'pkg_resources' 错误。

编程语言 2026-07-07

我想对数据集执行ydata_profiling,但每当我运行ydata_profiling的代码时,它就会显示这个错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 1
----> 1 import ydata_profiling
      2 from ydata_profiling import ProfileReport
      3 profile = ProfileReport(df, title="Profiling Report")

File c:\Users\muham\.conda\envs\AutoEDA\lib\site-packages\ydata_profiling\__init__.py:10
      6 import warnings  # isort:skip # noqa
      8 import importlib.util  # isort:skip # noqa
---> 10 from ydata_profiling.compare_reports import compare  # isort:skip # noqa
     11 from ydata_profiling.controller import pandas_decorator  # isort:skip # noqa
     12 from ydata_profiling.profile_report import ProfileReport  # isort:skip # noqa

File c:\Users\muham\.conda\envs\AutoEDA\lib\site-packages\ydata_profiling\compare_reports.py:12
     10 from ydata_profiling.model import BaseDescription
     11 from ydata_profiling.model.alerts import Alert
---> 12 from ydata_profiling.profile_report import ProfileReport
     15 def _should_wrap(v1: Any, v2: Any) -> bool:
     16     if isinstance(v1, (list, dict)):

File c:\Users\muham\.conda\envs\AutoEDA\lib\site-packages\ydata_profiling\profile_report.py:11
      9 with warnings.catch_warnings():
     10     warnings.simplefilter("ignore")
---> 11     import pkg_resources
     13 if not is_pyspark_installed():
     14     from typing import TypeVar

ModuleNotFoundError: No module named 'pkg_resources'

我也尝试安装了 "pkg_resources" 和 "setuptools",并尝试升级它们,但每次都显示相同的错误。

Code of above error:

import ydata_profiling
from ydata_profiling import ProfileReport
profile = ProfileReport(df, title="Profiling Report")

我也尝试使用最新版本的数据分析工具fg_data_profiling,但仍然显示相同的错误。

解决方案

可能这个错误发生是因为 setuptools 在你的Python环境中缺失或损坏,因此 pkg_resources 无法导入。
ydata_profiling 依赖 pkg_resources,它来自 setuptools

请尝试以下方法。

运行: conda install setuptools --force-reinstall
然后重启Jupyter/VS Code内核。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章