"No nvcc in $PATH" output, compiling an extension with CPU optimized pytorch

If I try to compile a C++ extension (both JIT and setup.py variants) the first line of output is

which: no nvcc in ($PATH)

where $PATH is my actual path.

Since I installed the CPU optimized version without CUDA on my machine, I wonder whether this hints at either a problem in my installation or a bug.

My version is ‘1.3.1+cpu’, but the same occurs also for the nightly build. My python version is 3.7 and I installed with pip in a virtual environment.

Are you providing any CUDA source files or use with_cuda=True?
I just tested a simple C++ extension on my non-GPU machine and it worked fine:

cpp_source = '''
torch::Tensor my_fun(torch::Tensor z) {
  auto s = torch::relu(z);
  return s;
}
'''

module = load_inline(name='inline_extension',
                     cpp_sources=[cpp_source],
                     functions=['my_fun'])

module.my_fun(torch.randn(10))

Loading extensions works fine, I asked this because I really have another issue I’m trying to troubleshoot, see here: Tensor.backward called within C++ extension hangs.

I am just confused why that line appears and whether it might indicate a problem.
Here is what I get for your specific example

>>> import torch, os
>>> os.environ['CXX'] = 'g++'  # my default is c++, which fails
>>> from torch.utils.cpp_extension import load_inline
which: no nvcc in (/home/...:... i.e. my $PATH)
>>> cpp_source = '''
... torch::Tensor my_fun(torch::Tensor z) {
...   auto s = torch::relu(z);
...   return s;
... }
... '''
>>> module = load_inline(name='inline_extension', cpp_sources=[cpp_source], functions=['my_fun'])
>>> module.my_fun(torch.randn(10))  # everything fine.

Pytorch is only installed in the virtual environment, using pip. Do you not get the “no nvcc” line? For reference, here is exactly how I installed pytorch from scratch:

python3.7 -m venv env
source env/bin/activate
pip3 install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html

No, I don’t get the message regarding the missing nvcc when I execute the code.
Is this just a warning and your module still works or does it raise an error?

It seems to be just a warning, since the module works. However, the message doesn’t look intentional which is why I to asked if something might be wrong.

I’m not sure, why this warning is thrown and it seems PyTorch thinks you are trying to load a CUDA extension.
Do you have any paths or arguments in your environment, which could point to a (non-existing) nvcc or some CUDA folders?

I think this is caused by this code:

that’s executed unconditionally when building extensions.

If it’s not causing an actual failure and is just alarming, you might be able to shut it up by setting CUDA_HOME or CUDA_PATH in the env even without CUDA installed.