TFPreTrainedModel.prepare_tf_dataset() gives ImportError: Datasets module not found; but it is installed and usable (load_dataset() works)
Author: swap-10
Pull request: no

### System Info

Google Colab CPU Instance

- `transformers` version: 4.23.1
- Platform: Linux-5.10.133+-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.7.15
- Huggingface_hub version: 0.10.1
- PyTorch version (GPU?): 1.12.1+cu113 (False)
- Tensorflow version (GPU?): 2.9.2 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: Yes (However, the issue occurs even when not using parallel setup)

### Who can help?

@LysandreJik 

### Information

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

### Tasks

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

### Reproduction

I was trying to follow along [this nb from the notebooks repo](https://github.com/huggingface/notebooks/blob/main/examples/language_modeling-tf.ipynb)
This is the [Colab link](https://colab.research.google.com/drive/13OGs8d2N-bAirSWslbNx6kffttwdKXJg?usp=sharing) of my attempt, with the outputs (and the error)

### Expected behavior

Detect that the Datasets package is present and use it as required.

Maybe there's a really silly mistake I'm making but I really cannot figure out what it could be and I couldn't find any similar results online.

Thanks in advance!

Comments:
cc @Rocketknight1 

I reproduced the error here, working on it now! I suspect this is caused by the recent release of a new version of `datasets`

Hi, I've diagnosed the issue. It is not related to TF or `prepare_tf_dataset` at all. Instead, the problem is caused by the following:

1) `pip install transformers` followed by importing it, then by initializing one or more model classes
2) `pip install datasets` **after** we've imported and used a class from `transformers`

If you do this, `transformers.is_datasets_available()` returns `False`. I believe the underlying reason is that `transformers` imports some libraries (most likely `urllib3`), and then even if `datasets` installs newer versions, they cannot be re-imported until you restart your session. 

@swap-10 As a short-term workaround, you can simply install `transformers` and `datasets` together in the first block, and then your code should work fine.

cc @lhoestq and @sgugger - can we update the pinned version of `urllib3` for `transformers` to stop this happening? Here's [a short Colab](https://colab.research.google.com/drive/1Ydi_fJe4xtL9zV3PZXrbG8iZUZP9P_0N?usp=sharing) to reproduce the issue. The issue occurs both when I install `transformers` from `main` or when I use the latest release version.

Update: Manually pinning urllib3 in the colab didn't work - the problem is another library. Trying to figure it out!

Wait, this is just me being stupid. This is caused by us caching `_datasets_available` in `import_utils`. As a result, this will always happen if you import and use transformers classes before you `pip install datasets` because this will cache a value of `False` until you restart your runtime. There's no bug to fix here in `transformers` - @swap-10 you just need to install `datasets` before importing `transformers`!

Thanks for digging into this @Rocketknight1 !

> Wait, this is just me being stupid. This is caused by us caching `_datasets_available` in `import_utils`. As a result, this will always happen if you import and use transformers classes before you `pip install datasets` because this will cache a value of `False` until you restart your runtime. There's no bug to fix here in `transformers` - @swap-10 you just need to install `datasets` before importing `transformers`!

Interesting. Thank you! I used Dataset.to_tf_dataset() meanwhile to get my work done.

However, I guess this isn't exactly anticipatable behaviour? Perhaps this should at least be mentioned somewhere in the documentation? (if it isn't already)

It's quite niche, but I agree it can be confusing for users. @sgugger I could make a PR to change the warning messages to ask users to restart their runtimes if they installed a dependency after importing `transformers`, WDYT?

If you can catch it properly, why not yes!

Closing this issue now that we've added the user warnings about restarting the runtime