Can seemingly not build cpp/cuda extensions for any version of pytorch/cudatoolkit

ZimoNitrome: <p>I am currently trying to compile <a href="https://github.com/pytorch/extension-cpp" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pytorch/extension-cpp: C++ extensions in PyTorch</a> just as a benchmark but it keeps failing with the same error message:</p>
<p>I cloned the repo and tried running:</p>
<p><code>../extension-cpp/cpp&gt; python .\setup.py install</code></p>
<p>This is the full output I get:</p>
<pre><code class="lang-auto">No CUDA runtime is found, using CUDA_HOME='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1'
running install
running bdist_egg
running egg_info
writing lltm_cpp.egg-info\PKG-INFO
writing dependency_links to lltm_cpp.egg-info\dependency_links.txt
writing top-level names to lltm_cpp.egg-info\top_level.txt
reading manifest file 'lltm_cpp.egg-info\SOURCES.txt'
writing manifest file 'lltm_cpp.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_ext
C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py:287: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified
  warnings.warn('Error checking compiler version for {}: {}'.format(compiler, error))
building 'lltm_cpp' extension
Emitting ninja build file G:\&lt;user&gt;\Documents\programming\github\extension-cpp\cpp\build\temp.win-amd64-3.9\Release\build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/1] cl /showIncludes /nologo /Ox /W3 /GL /DNDEBUG /MD /MD /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /EHsc -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include\torch\csrc\api\include -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include\TH -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include\THC -IC:\Users\&lt;user&gt;\Anaconda3\include -IC:\Users\&lt;user&gt;\Anaconda3\include "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include" -c G:\&lt;user&gt;\Documents\programming\github\extension-cpp\cpp\lltm.cpp /FoG:\&lt;user&gt;\Documents\programming\github\extension-cpp\cpp\build\temp.win-amd64-3.9\Release\lltm.obj -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=lltm_cpp -D_GLIBCXX_USE_CXX11_ABI=0 /std:c++14
FAILED: G:/&lt;user&gt;/Documents/programming/github/extension-cpp/cpp/build/temp.win-amd64-3.9/Release/lltm.obj
cl /showIncludes /nologo /Ox /W3 /GL /DNDEBUG /MD /MD /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /EHsc -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include\torch\csrc\api\include -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include\TH -IC:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\include\THC -IC:\Users\&lt;user&gt;\Anaconda3\include -IC:\Users\&lt;user&gt;\Anaconda3\include "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include" -c G:\&lt;user&gt;\Documents\programming\github\extension-cpp\cpp\lltm.cpp /FoG:\&lt;user&gt;\Documents\programming\github\extension-cpp\cpp\build\temp.win-amd64-3.9\Release\lltm.obj -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=lltm_cpp -D_GLIBCXX_USE_CXX11_ABI=0 /std:c++14
CreateProcess failed: The system cannot find the file specified.
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py", line 1533, in _run_ninja_build
    subprocess.run(
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "G:\&lt;user&gt;\Documents\programming\github\extension-cpp\cpp\setup.py", line 9, in &lt;module&gt;
    setup(
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\command\install.py", line 67, in run
    self.do_egg_install()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\command\bdist_egg.py", line 164, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\command\bdist_egg.py", line 150, in call_command
    self.run_command(cmdname)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\command\install_lib.py", line 11, in run
    self.build()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\command\install_lib.py", line 107, in build
    self.run_command('build_ext')
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\command\build_ext.py", line 79, in run
    _build_ext.run(self)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\command\build_ext.py", line 340, in run
    self.build_extensions()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py", line 670, in build_extensions
    build_ext.build_extensions(self)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 195, in build_extensions
    _build_ext.build_ext.build_extensions(self)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\command\build_ext.py", line 449, in build_extensions
    self._build_extensions_serial()
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial
    self.build_extension(ext)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\setuptools\command\build_ext.py", line 196, in build_extension
    _build_ext.build_extension(self, ext)
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\distutils\command\build_ext.py", line 529, in build_extension
    objects = self.compiler.compile(sources,
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py", line 643, in win_wrap_ninja_compile
    _write_ninja_file_and_compile_objects(
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py", line 1250, in _write_ninja_file_and_compile_objects
    _run_ninja_build(
  File "C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py", line 1555, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error compiling objects for extension
</code></pre>
<p>I have tried installing every version of torch 1.7 - 1.11 and cudatoolkit 10.0 - 11.3 but nothing helps.</p>
<p>I am running torch in conda with python 3.9 on Windows with a RTX3090 GPU.</p>
<p>Any help?</p>

ZimoNitrome: <p>This was actually an error with Visual Stufio being installed incorrectly. I uninstalled all Vsiual Studio components, removed the environtment variables (named ones and from Path), and removed all files on my disk. Then I installed VS 2019 (As that is the latest supported version by PyTorch as of making this post) and installed the C++ dev tools (SDK, build tools) with it. I then had to re-install Pytorch in conda (conda uninstall pytorch torchvision torchaudio cudatoolkit) and then installed them again, simply replacing the existing packages did not work.</p>
<p>After all this, it finally worked.</p>

cmauceri: <p>How did you figure out that Visual Studio was the problem? I have a similar error and I’m trying to assess whether your solution will work for me.</p>

ZimoNitrome: <p>I didn’t really. I tried uninstalling every single component until it worked. VS was the last component.</p>
<p>But I can guess that:</p>
<aside class="quote no-group" data-username="ZimoNitrome" data-post="1" data-topic="135073">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zimonitrome/48/27591_2.png" class="avatar"> ZimoNitrome:</div>
<blockquote>
<pre><code class="lang-auto">C:\Users\&lt;user&gt;\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py:287: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified
  warnings.warn('Error checking compiler version for {}: {}'.format(compiler, error))
</code></pre>
</blockquote>
</aside>
<p>and</p>
<aside class="quote no-group" data-username="ZimoNitrome" data-post="1" data-topic="135073">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zimonitrome/48/27591_2.png" class="avatar"> ZimoNitrome:</div>
<blockquote>
<pre><code class="lang-auto">CreateProcess failed: The system cannot find the file specified.
</code></pre>
</blockquote>
</aside>
<p>points towards torch not finding correct VS version.</p>
<p>Good luck.</p>