Can not import Trainer 
Author: Eleo22
Pull request: no
Labels: name: bug

### System Info

python 3.9
I install transformer with pip install transformer. 
Using a terminar I open python from:
>from transformers import  Trainer

I get:
`Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 957, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/transformers/trainer.py", line 176, in <module>
    import datasets
  File "/usr/local/lib/python3.7/site-packages/keras/datasets/__init__.py", line 3, in <module>
    from . import mnist
  File "/usr/local/lib/python3.7/site-packages/keras/datasets/mnist.py", line 7, in <module>
    from ..utils.data_utils import get_file
ImportError: attempted relative import beyond top-level package

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1055, in _handle_fromlist
  File "/usr/local/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 947, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/usr/local/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 959, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.trainer because of the following error (look up to see its traceback):
attempted relative import beyond top-level package`


Any idea how I can fix it ?

Many thanks,
Ele 



### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

from transformers import  Trainer

### Expected behavior

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 957, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/transformers/trainer.py", line 176, in <module>
    import datasets
  File "/usr/local/lib/python3.7/site-packages/keras/datasets/__init__.py", line 3, in <module>
    from . import mnist
  File "/usr/local/lib/python3.7/site-packages/keras/datasets/mnist.py", line 7, in <module>
    from ..utils.data_utils import get_file
ImportError: attempted relative import beyond top-level package

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1055, in _handle_fromlist
  File "/usr/local/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 947, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/usr/local/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 959, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.trainer because of the following error (look up to see its traceback):
attempted relative import beyond top-level package
>>> 


Comments:
Hey @Eleo22, that's interesting, it seems that `import datasets` in the trainer led to an import of the `keras.datasets` package.

Do you know why that might be? Could you try to uninstall keras (you don't need it for the trainer) and to reinstall `datasets` ? Thanks!

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.