Pipeline can't find torch or tensorflow, errors out in notebook.
Author: robertdecaire
Pull request: no

### System Info

- huggingface_hub version: 0.22.0
- Platform: Windows-11-10.0.22631-SP0
- Python version: 3.12.2
- Running in iPython ?: No
- Running in notebook ?: 
- Running in Google Colab ?: No
- Token path ?: C:\Users\rober\.cache\huggingface\token
- Has saved token ?: False
- Configured git credential helpers: manager
- FastAI: N/A
- Tensorflow: 2.16.1
- Torch: 2.2.1
- Jinja2: 3.1.3
- Graphviz: N/A
- keras: 3.1.1
- Pydot: N/A
- Pillow: N/A
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 1.26.4
- pydantic: N/A
- aiohttp: N/A
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: C:\Users\rober\.cache\huggingface\hub
- HF_ASSETS_CACHE: C:\Users\rober\.cache\huggingface\assets
- HF_TOKEN_PATH: C:\Users\rober\.cache\huggingface\token
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10

### Who can help?

_No response_

### Information

- [X] 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

I'm also having a similar problem to https://github.com/huggingface/transformers/issues/27214 on Windows 11, trying to run the code from one of the tutorials in Jupyter Lab:

```
from transformers import pipeline

translator = pipeline(task="translation", model="facebook/nllb-200-distilled-600M")
```
This gives me a similar error to that issue: `RuntimeError: At least one of TensorFlow 2.0 or PyTorch should be installed.`

Following the suggestion in that issue, if I run:
```
import torch

from transformers import is_torch_available

print(torch.__version__)
print(is_torch_available())
```
I get:
```
2.2.1+cpu
False
```
I went into the repo and reproduced the code (i.e. copy-pasted it) in import_utils.py that defines `is_torch_available()` into a notebook and set the environment variables:
```
USE_TORCH=1
USE_TF=0
```
This caused my reproduced code to return `true` for `is_torch_available()`, but the actual call that's being made in my notebook is returning `false` for whatever reason. The notebook running the reproduced code can find the environment variables, and it can find the package, and it can identify the package version (2.2.1), but this doesn't work when the library version of the function is called.

### Expected behavior

It should return `true` for `is_torch_available()`, leading to the correct execution of the line from the tutorial.

Comments:
cc @Rocketknight1 and maybe @ydshieh 🤗 

I suspect this is related to the code in `import_utils` that tries to get the package version and returns a complete failure if it can't. I think this needs a rewrite, since it's clear that sometimes the version lookup fails, but the package is definitely present. I'm happy to take it @ydshieh, unless you really want to!

cc @robertdecaire, I've written an attempted fix at #29884! Can you check it out and let me know if it works for you? You can install from the PR branch with `pip install git+https://github.com/huggingface/transformers.git@improve_torch_version_check`

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.