Repository: huggingface/transformers

Issue:
import error in version 3.3.0, conflict with local directory "datasets"
## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version: 3.3.0
- Platform: Google Colab



Model I am using ：Bert


## To reproduce

Steps to reproduce the behavior:

Traceback (most recent call last):
  File "train.py", line 19, in <module>
    from mydataset import load_data,dist_load_data,load_data2
  File "/content/drive/My Drive/mrc4ner/mydataset.py", line 5, in <module>
    from transformers import BertTokenizer
  File "/usr/local/lib/python3.6/dist-packages/transformers/__init__.py", line 22, in <module>
    from .integrations import (  # isort:skip
  File "/usr/local/lib/python3.6/dist-packages/transformers/integrations.py", line 42, in <module>
    from .trainer_utils import PREFIX_CHECKPOINT_DIR, BestRun  # isort:skip
  File "/usr/local/lib/python3.6/dist-packages/transformers/trainer_utils.py", line 6, in <module>
    from .file_utils import is_tf_available, is_torch_available, is_torch_tpu_available
  File "/usr/local/lib/python3.6/dist-packages/transformers/file_utils.py", line 72, in <module>
    logger.debug(f"Succesfully imported datasets version {datasets.__version__}")
AttributeError: module 'datasets' has no attribute '__version__'
## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->

My code works well before, and there is a "datasets" folder in my working directory.  When my transformers version upgraded to 3.3.0, I get this error. If I change the name of the folder "datasets" or downgrade transformers to version 3.2.0, the error is get fixed.
Is this a bug?  Because it doesn't allow me to use "datasets" as a folder name.


Discussion:
Sadly that is how python works, it will try to import the datasets library from a local folder if you have a folder named like this in the path your are working in. However, this should only work if there is a `__init__.py` in your folder named datasets. Removing that file should then solve the bug.
This change just broke [DeepChem](https://github.com/deepchem/deepchem).  In the short term we can work around it by pinning to an older version, but that's not a reasonable long term solution.  Directories called "datasets" are very common, and this will impact a lot of people.  Using a common, generic word as the top level package violates the [PEP 423](https://www.python.org/dev/peps/pep-0423/) guidelines for package naming.
Indeed, we are working on a fix and will release soon.

Resolving patch:
diff --git a/src/transformers/file_utils.py b/src/transformers/file_utils.py
--- a/src/transformers/file_utils.py
+++ b/src/transformers/file_utils.py
@@ -68,8 +68,12 @@
 try:
     import datasets  # noqa: F401
 
-    _datasets_available = True
-    logger.debug(f"Succesfully imported datasets version {datasets.__version__}")
+    # Check we're not importing a "datasets" directory somewhere
+    _datasets_available = hasattr(datasets, "__version__") and hasattr(datasets, "load_dataset")
+    if _datasets_available:
+        logger.debug(f"Succesfully imported datasets version {datasets.__version__}")
+    else:
+        logger.debug("Imported a datasets object but this doesn't seem to be the 🤗 datasets library.")
 
 except ImportError:
     _datasets_available = False


Test patch: