Repository: pytorch
Issue: Fault and vauge error when invoking nvcc: The system cannot find the file specified
Labels: module: windows,module: cpp-extensions,triaged

### 🐛 Describe the bug

The issue is torch faulting unexpectedly and not reporting anything useful on windows. I ran into the issue trying to run setup_cuda in https://github.com/qwopqwop200/GPTQ-for-LLaMa.git
which gave me a mysterious
```
error: [WinError 2] The system cannot find the file specified
```
After debugging setup_cuda with pdb, I found that this came from the torch library.

To reproduce:
The first part of the issue is a faulty CUDA_HOME being set in `cpp_extensions._find_cuda_home` because it finds it through `where nvcc` which outputs two different ones.
```python
import subprocess
import os
from torch.utils import cpp_extension

print(subprocess.check_output(['where', 'nvcc'], stderr=open(os.devnull, 'w')))
print(cpp_extension._find_cuda_home())
```
which yields
```
b'C:\\Users\\zakar\\miniconda3\\envs\\tgwui\\Library\\bin\\nvcc.exe\r\nC:\\Users\\zakar\\miniconda3\\envs\\tgwui\\bin\\nvcc.exe\r\n'
'C:\\Users\\zakar\\miniconda3\\envs\\tgwui\\Library\\bin\\nvcc.exe\r\nC:\\Users\\zakar\\miniconda3\\envs\\tgwui'
```

This is then used when checking cuda's version, the following reproduces my specific configuration:

```python
from torch.utils import cpp_extension
cpp_extension._check_cuda_version('cl', '19.29.30148')
```
which yields
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\zakar\miniconda3\envs\tgwui\Lib\site-packages\torch\utils\cpp_extension.py", line 376, in _check_cuda_version
    cuda_version_str = subprocess.check_output([nvcc, '--version']).strip().decode(*SUBPROCESS_DECODE_ARGS)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\zakar\miniconda3\envs\tgwui\Lib\subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\zakar\miniconda3\envs\tgwui\Lib\subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\zakar\miniconda3\envs\tgwui\Lib\subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\zakar\miniconda3\envs\tgwui\Lib\subprocess.py", line 1509, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
```

Through my cuda setup I only saw it output this "[WinError 2] The system cannot find the file specified" without any clarification, so this case should be handled and alerted.

### Versions

```
Collecting environment information...
PyTorch version: 2.0.1
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11 Home
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.20.21032501-MSVC_2
Libc version: N/A

Python version: 3.11.3 | packaged by Anaconda, Inc. | (main, Apr 19 2023, 23:46:34) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.22621-SP0
Is CUDA available: True
CUDA runtime version: 11.7.64
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 2060
Nvidia driver version: 531.68
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture=9
CurrentClockSpeed=2592
DeviceID=CPU0
Family=198
L2CacheSize=1536
L2CacheSpeed=
Manufacturer=GenuineIntel
MaxClockSpeed=2592
Name=Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
ProcessorType=3
Revision=

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.0.1
[pip3] torchaudio==2.0.2
[pip3] torchvision==0.15.2
[conda] blas                      1.0                         mkl
[conda] cudatoolkit               11.3.1               h59b6b97_2
[conda] cudatoolkit-dev           11.7.0               h9f2f4db_6    conda-forge
[conda] mkl                       2023.1.0         h8bd8f75_46356
[conda] mkl-service               2.4.0           py311h2bbff1b_1
[conda] mkl_fft                   1.3.6           py311hf62ec03_1
[conda] mkl_random                1.2.2           py311hf62ec03_1
[conda] numpy                     1.24.3          py311hdab7c0b_1
[conda] numpy-base                1.24.3          py311hd01c5d8_1
[conda] pytorch                   2.0.1           py3.11_cuda11.7_cudnn8_0    pytorch
[conda] pytorch-cuda              11.7                 h16d0643_5    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                2.0.2                    pypi_0    pypi
[conda] torchvision               0.15.2                   pypi_0    pypi
```

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm @vladimir-aubrecht @malfet @zou3519