ImportError: cannot import name 'X' from 'datasets' (load_metric, list_datasets, ...): which releases have it
Most of these errors come from datasets 3.0.0 (2024-09-11), which removed 30 top-level names; 2.21.0 is the last release that has them. load_metric, list_metrics and Metric moved to the Evaluate library (evaluate.load). list_datasets is now huggingface_hub.list_datasets. set_caching_enabled is now enable_caching or disable_caching. The task templates, such as TextClassification, were dropped with no replacement in datasets. To run old code unchanged, pin pip install "datasets<3.0.0". For any other name, in any module of datasets, paste the error below.
Corrected on 2026-12-05: this page read only the first release of each minor version, so a name added or removed in a patch release was dated to the next minor. For example, from datasets import StreamingDownloadManager works from 2.2.2 (2022-05-20), not only from 2.3.0. Every release was then read once from PyPI: 22 top-level names (and 502 module-and-name pairs in all) differ in some patch release from the first release of the same minor. The lookup now gives those patch releases. The per-minor ranges are unchanged.
Examples:
Runs in your browser on datasets.json (152 KB); nothing you paste is sent anywhere. Covers 237 top-level names and 4,933 module-and-name pairs in 189 modules.
What did datasets 3.0.0 remove, and what replaces each name?
These 30 names left from datasets import ... in 3.0.0; each replacement is quoted from the deprecation notes in 2.21.0.
| Removed in 3.0.0 | Use instead |
|---|---|
AudioClassification | none in datasets (task templates were dropped) |
AutomaticSpeechRecognition | none in datasets (task templates were dropped) |
BeamBasedBuilder | none named |
ExpectedMoreDownloadedFiles | none named |
ExpectedMoreSplits | none named |
ImageClassification | none in datasets (task templates were dropped) |
LanguageModeling | none in datasets (task templates were dropped) |
Metric | evaluate (the object evaluate.load returns) |
MetricInfo | evaluate |
QuestionAnsweringExtractive | none in datasets (task templates were dropped) |
Summarization | none in datasets (task templates were dropped) |
TaskTemplate | none in datasets (task templates were dropped) |
TextClassification | none in datasets (task templates were dropped) |
UnexpectedDownloadedFile | none named |
UnexpectedSplits | none named |
_arrow_dataset | none named |
_deprecated_download_manager | none named |
_deprecated_info_utils | none named |
_utils | none named |
beam_utils | none named |
download_manager | none named |
inspect_dataset | none named |
inspect_metric | evaluate.inspect_evaluation_module |
list_datasets | huggingface_hub.list_datasets |
list_metrics | evaluate.list_evaluation_modules |
load_metric | evaluate.load |
metric | none named |
readme | none named |
set_caching_enabled | datasets.enable_caching / datasets.disable_caching |
tasks | none named |
What did each datasets release remove from datasets and datasets.utils?
119 of the 237 names that from datasets import has ever accepted are gone from 5.2.0. Most of the rest left in 1.4.0 and 2.0.0, when the top level stopped passing along everything datasets.utils imported (names like Optional and dill). 36 of the 189 modules that have existed are gone as well; paste No module named 'datasets...' into the lookup for any of them.
| Release | Date (PyPI) | Module | Names | Removed names |
|---|---|---|---|---|
| 4.5.0 | 2026-01-14 | datasets | 1 | keyhash |
| 3.0.0 | 2024-09-11 | datasets | 30 | AudioClassification, AutomaticSpeechRecognition, BeamBasedBuilder, ExpectedMoreDownloadedFiles, ExpectedMoreSplits, ImageClassification, LanguageModeling, Metric, MetricInfo, QuestionAnsweringExtractive, Summarization, TaskTemplate, TextClassification, UnexpectedDownloadedFile, UnexpectedSplits, _arrow_dataset, _deprecated_download_manager, _deprecated_info_utils, _utils, beam_utils, download_manager, inspect_dataset, inspect_metric, list_datasets, list_metrics, load_metric, metric, readme, set_caching_enabled, tasks |
| 3.0.0 | 2024-09-11 | datasets.utils | 3 | beam_utils, download_manager, readme |
| 2.19.0 | 2024-04-19 | datasets.utils | 1 | _datasets_server |
| 2.16.0 | 2023-12-22 | datasets.utils | 1 | __all__ |
| 2.14.0 | 2023-07-24 | datasets | 2 | platform, pyarrow |
| 2.11.0 | 2023-03-29 | datasets.utils | 1 | _hf_hub_fixes |
| 2.6.0 | 2022-10-13 | datasets | 1 | SCRIPTS_VERSION |
| 2.3.0 | 2022-06-14 | datasets.utils | 5 | DownloadConfig, DownloadManager, DownloadMode, mock_download_manager, streaming_download_manager |
| 2.0.0 | 2022-03-15 | datasets | 33 | ArrowReader, ArrowWriter, GenerateMode, KeyHasher, MockDownloadManager, NonMutableDict, _version, cached_path, classproperty, copyfunc, dumps, first_non_null_value, flatten_nest_dict, has_sufficient_disk_space, hf_bucket_url, import_main_class, is_remote_url, map_nested, memoize, mock_download_manager, no_op_if_value_is_null, prepare_module, relative_to_absolute_path, set_progress_bar_enabled, size_str, streaming_download_manager, temp_seed, temporary_assignment, total_allocated_bytes, tqdm_utils, unique_values, zip_dict, zip_nested |
| 2.0.0 | 2022-03-15 | datasets.utils | 24 | GenerateMode, MockDownloadManager, NonMutableDict, cached_path, classproperty, copyfunc, dumps, first_non_null_value, flatten_nest_dict, has_sufficient_disk_space, hf_bucket_url, is_remote_url, map_nested, memoize, no_op_if_value_is_null, relative_to_absolute_path, set_progress_bar_enabled, size_str, temp_seed, temporary_assignment, tqdm_utils, unique_values, zip_dict, zip_nested |
| 1.16.0 | 2021-11-26 | datasets | 1 | hf_api |
| 1.14.0 | 2021-10-19 | datasets | 1 | async_tqdm |
| 1.14.0 | 2021-10-19 | datasets.utils | 1 | async_tqdm |
| 1.4.0 | 2021-03-03 | datasets | 42 | Callable, ClassVar, CodeType, EmptyTqdm, Final, FunctionType, Generic, INFO, Literal, Optional, Pickler, Pool, RLock, StringIO, Tuple, Union, WARNING, abstractclassmethod, contextlib, datasets_dir, dill, disk_usage, dump, flatten_nested, functools, get_datasets_path, get_logger, get_verbosity, is_notebook, itertools, logger, memoized_property, np, os, pickle, pklregister, regex, save_function, set_verbosity_warning, sys, tqdm_lib, types |
| 1.4.0 | 2021-03-03 | datasets.utils | 42 | Callable, ClassVar, CodeType, EmptyTqdm, Final, FunctionType, Generic, INFO, Literal, Optional, Pickler, Pool, RLock, StringIO, Tuple, Union, WARNING, abstractclassmethod, contextlib, datasets_dir, dill, disk_usage, dump, flatten_nested, functools, get_datasets_path, get_logger, get_verbosity, is_notebook, itertools, logger, memoized_property, np, os, pickle, pklregister, regex, save_function, set_verbosity_warning, sys, tqdm_lib, types |
| 1.3.0 | 2021-02-15 | datasets | 5 | HF_DATASETS_CACHE, HF_METRICS_CACHE, is_beam_available, is_tf_available, is_torch_available |
| 1.3.0 | 2021-02-15 | datasets.utils | 5 | HF_DATASETS_CACHE, HF_METRICS_CACHE, is_beam_available, is_tf_available, is_torch_available |
| 1.2.0 | 2021-01-04 | datasets | 2 | datasets, metrics |
| 1.1.0 | 2020-10-02 | datasets | 1 | SCRIPTS_VERIONS |
How do I read the error?
- The path in parentheses is the copy of datasets that was imported. If it points into your project (a folder or a file named
datasets), that shadows the library: rename yours.(unknown location)means adatasetsfolder without__init__.pywas found first. - The module after "from" decides which table applies:
from 'datasets'is the top level,from 'datasets.arrow_writer'is that module. When another library raises it (trl, for example, importsSchemaInferenceErrorfromdatasets.arrow_writer, which exists from 2.7.0), upgrade datasets, not that library. - In a notebook, restart the kernel after
pip install -U datasets; the old copy stays loaded until then.
How was this read, and how was it checked?
From the source of each release tag, with Python's ast module; no release was installed or imported. datasets imports eagerly, so a module's names are everything it binds at module level: classes, functions, assignments, imports, and what from .x import * brings in. Code under if TYPE_CHECKING: is skipped. Dates come from PyPI.
Checks, by a second reading: (1) each of the 237 top-level names is found as plain text in __init__.py (or in the modules it star-imports) in every release of its range (7,032 name-and-release pairs), and is not imported there in the release on either side (178 edges). (2) A regular expression finds 23,287 definitions in 1,826 file versions; all are among the names read. (3) 8 known facts hold, among them the release named in the public reports under Sources.
Limits
- Nothing was installed or run. "Has it" means the import statement resolves in the source.
- The ranges use the first release of each minor version (and the newest). Every release was also read once (120 releases, from the wheels on PyPI, with the same rules): 22 top-level names and 502 module-and-name pairs in all differ in some patch release from the first release of their minor. The lookup prints those patch releases under the range.
- A star import of a package carries along the submodules that package has loaded; the lookup counts all of its submodules, so for a few old releases it may list a submodule name at the top level that was not loaded yet.
- Errors that are not about import names, such as dataset loading scripts no longer being run, are not covered.
Questions
How do I fix "cannot import name 'load_metric' from 'datasets'"?
datasets 3.0.0 (2024-09-11) removed load_metric; 2.21.0 is the last release with it. Install the Evaluate library and use evaluate.load: pip install evaluate, then import evaluate; metric = evaluate.load("accuracy"). To keep old code unchanged, pin pip install "datasets<3.0.0".
What else did datasets 3.0.0 remove?
30 top-level names: load_metric, list_metrics, inspect_metric, Metric and MetricInfo (moved to Evaluate), list_datasets (use huggingface_hub.list_datasets), set_caching_enabled (use enable_caching or disable_caching), inspect_dataset, the task templates such as TextClassification, and a few modules. The full list is on this page.
How do I fix "cannot import name 'list_datasets' from 'datasets'"?
Use huggingface_hub.list_datasets, which datasets 2.21.0 already pointed to. datasets 3.0.0 removed its own list_datasets.
The error says "cannot import name ... from 'datasets'" and the path ends in a folder of my project. What is wrong?
A file or folder named datasets in your project (or an old datasets.py) is imported instead of the library. The path in parentheses shows which one; rename yours. The same holds for "unknown location", which means a datasets folder without __init__.py.
Does this page cover names below the top level, like datasets.utils or datasets.arrow_writer?
Yes: every module of datasets from 1.0.0 to 5.2.0, 4,933 module-and-name pairs in 189 modules.
Sources
- huggingface/datasets, release tags 1.0.0 to 5.2.0: every
.pyfile under src/datasets; release dates from PyPI. - Notes quoted: load.py at 2.21.0 (load_metric), inspect.py at 2.21.0 (list_datasets, list_metrics, inspect_metric), fingerprint.py at 2.21.0 (set_caching_enabled).
- Reports: Can't import load_metric from datasets, SchemaInferenceError from datasets.arrow_writer, raised by trl.
The same data as JSON: datasets.json, licensed CC BY 4.0.
Related: "cannot import name ... from 'transformers'" · "... from 'huggingface_hub'" · "... from 'peft', 'trl' or 'accelerate'" · "... from 'diffusers'".