Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import datasets AttributeError: partially initialized module 'datasets' has no attribute 'utils' (most likely due to a circular import) #4906

Closed
OPterminator opened this issue Aug 28, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@OPterminator
Copy link

OPterminator commented Aug 28, 2022

Describe the bug

A clear and concise description of what the bug is.
Not able to import datasets

Steps to reproduce the bug

# Sample code to reproduce the bug
import os
os.environ["WANDB_API_KEY"] = "0" ## to silence warning
import numpy as np
import random
import sklearn
import matplotlib.pyplot as plt
import pandas as pd
import sys
import tensorflow as tf
import plotly.express as px
import transformers
import tokenizers
import nlp as nlp
import utils
import datasets

Expected results

A clear and concise description of the expected results.
import should work normal

Actual results

Specify the actual results or traceback.

AttributeError Traceback (most recent call last)
in
13 import nlp as nlp
14 import utils
---> 15 import datasets

~\anaconda3\lib\site-packages\datasets_init_.py in
44 from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
45 from .info import DatasetInfo, MetricInfo
---> 46 from .inspect import (
47 get_dataset_config_info,
48 get_dataset_config_names,

~\anaconda3\lib\site-packages\datasets\inspect.py in
28 from .download.streaming_download_manager import StreamingDownloadManager
29 from .info import DatasetInfo
---> 30 from .load import dataset_module_factory, import_main_class, load_dataset_builder, metric_module_factory
31 from .utils.file_utils import relative_to_absolute_path
32 from .utils.logging import get_logger

~\anaconda3\lib\site-packages\datasets\load.py in
53 from .iterable_dataset import IterableDataset
54 from .metric import Metric
---> 55 from .packaged_modules import (
56 _EXTENSION_TO_MODULE,
57 _MODULE_SUPPORTS_METADATA,

~\anaconda3\lib\site-packages\datasets\packaged_modules_init_.py in
4 from typing import List
5
----> 6 from .csv import csv
7 from .imagefolder import imagefolder
8 from .json import json

~\anaconda3\lib\site-packages\datasets\packaged_modules\csv\csv.py in
13
14
---> 15 logger = datasets.utils.logging.get_logger(name)
16
17 _PANDAS_READ_CSV_NO_DEFAULT_PARAMETERS = ["names", "prefix"]

AttributeError: partially initialized module 'datasets' has no attribute 'utils' (most likely due to a circular import)

Environment info

Copy-and-paste the text below in your GitHub issue.

  • datasets version: 2.4.0
  • Platform: Windows-10-10.0.22000-SP0
  • Python version: 3.8.8
  • PyArrow version: 9.0.0
  • Pandas version: 1.2.4
@OPterminator OPterminator added the bug Something isn't working label Aug 28, 2022
@albertvillanova
Copy link
Member

Thanks for reporting, @OPterminator.

However, we are not able to reproduce this issue.

There might be 2 reasons why you get this exception:

  • Either the name of your local Python file: if it is called datasets.py this could generate a circular import when trying to import the Hugging Face datasets library.
    • You could try to rename it and run it again.
  • Another cause could be the simultaneous use of the packages nlp and datasets. Please note that we renamed the Hugging Face nlp library to datasets more than 2 years ago: they are 2 versions of the same library.
    • Please try to update your script and use only datasets (nlp name is no longer in use and is out of date).

@burhankhanzada
Copy link

i am also facing this issue

----> 1 import datasets
      3 dataset = datasets.load_dataset("ucberkeley-dlab/measuring-hate-speech", "binary")
      4 df = dataset["train"].to_pandas()

File ~/.pyenv/versions/3.10.9/lib/python3.10/site-packages/datasets/__init__.py:52
     50 from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
     51 from .info import DatasetInfo, MetricInfo
---> 52 from .inspect import (
     53     get_dataset_config_info,
     54     get_dataset_config_names,
     55     get_dataset_infos,
     56     get_dataset_split_names,
     57     inspect_dataset,
     58     inspect_metric,
     59     list_datasets,
     60     list_metrics,
     61 )
     62 from .iterable_dataset import IterableDataset
     63 from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric

File ~/.pyenv/versions/3.10.9/lib/python3.10/site-packages/datasets/inspect.py:30
     28 from .download.streaming_download_manager import StreamingDownloadManager
...
---> 16 logger = datasets.utils.logging.get_logger(__name__)
     19 if datasets.config.PYARROW_VERSION.major >= 7:
     21     def pa_table_to_pylist(table):

@Baxkiller
Copy link

I am facing the same question. And this happens when i installing evaluate package while jupyter notebook running. I'm not sure if the error occured because of trying to import the package installed when the notebook is running. Surpringly when i stop the notebook and rerun, the issue has been solved itself. Hope this will be helpful : )

@beshkenadze
Copy link

I also got this error.
It helped me to find the python process and kill it, then restart the kernel and the error disappeared.

@ShuningCui
Copy link

I also got this error. It helped me to find the python process and kill it, then restart the kernel and the error disappeared.

Yes!

@lnxdx
Copy link

lnxdx commented Oct 27, 2023

I am facing the same question. And this happens when i installing evaluate package while jupyter notebook running. I'm not sure if the error occured because of trying to import the package installed when the notebook is running. Surpringly when i stop the notebook and rerun, the issue has been solved itself. Hope this will be helpful : )

Thank you! :)

@Gloriacyy
Copy link

Yes, i met the same error when import pandas after restarting computers.
AttributeError: partially initialized module 'pandas' has no attribute '_pandas_parser_CAPI' (most likely due to a circular import)
some think pandas.py file need to be found and delete, i tried but it did not work.
however, restarted the kernel and solved it!!!
Thanks very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants