PyTorch build from source on Windows

Yes, where msbuild gives me exactly

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe

btw I’m using pip, not conda for pip install numpy pyyaml mkl mkl-include setuptools cmake cffi typing ( I know that in readme the is note that conda is strongly recommended, but somehow I’m unable to set up conda on my machine). Maybe the problem is here?

No, conda is not the problem here. Would you please do python setup.py build and send the full log here. There must be some problem during the configuration of CMake.

Yes, I’ve run it and the full log is exactly like the one I provided in the question.

I don’t think so. This one is apparently not the root cause. Would you please do python setup.py build --cmake?

Yes! That did the work, after

python setup.py build --cmake
python setup.py install

pytorch was finally installed.
However

python
>>> import torch
>>> torch.cuda.is_available()

returns False. When I run torch.cuda.current_device() i get:
AssertionError: Torch not compiled with CUDA enabled

Can this be Nsight Compute issue?

Yes, may be. Please ensure CUDA and the Visual Studio extension are installed. If the env var %NVTOOLSEXT_PATH% exists, then it should be fine. Otherwise, please reinstall CUDA and remember to tick VS extension.

I reinstalled CUDA to 10.1, ensuring that both Nsight Compute and VS extensions are checked. Now when I try to build pytorch witch python setup.py build --cmake I get this error (note that some of the phrases were in polish, so I’ve translated them):

"C:\Users\MarcinM\pytorch\build\INSTALL.vcxproj" (default target) (1)->
"C:\Users\MarcinM\pytorch\build\ALL_BUILD.vcxproj" (default target) (3)->
"C:\Users\MarcinM\pytorch\build\caffe2\AlgorithmsTest.vcxproj" (default target) (4)->
"C:\Users\MarcinM\pytorch\build\caffe2\caffe2_gpu.vcxproj" (default target) (21)->
(CustomBuild target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(20
9,5): error MSB6006: "cmd.exe" exited with code 1. [C:\Users\MarcinM\pytorch\build\caffe2\caffe2_gpu.vcxp
roj]

    Warnings: 3661
    Errors: 1

Czas, który upłynął: 00:32:23.65
Traceback (most recent call last):
  File "setup.py", line 710, in <module>
    build_deps()
  File "setup.py", line 282, in build_deps
    build_dir='build')
  File "C:\Users\MarcinM\pytorch\tools\build_pytorch_libs.py", line 264, in build_caffe2
    cwd=build_dir, env=my_env)
  File "C:\Users\MarcinM\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release']' returned non-zero exit status 1.

I’ve also made clean build, but with no success. Any other thoughts?

Would you please run the building process inside VS (only caffe2_gpu is enough and make sure you choose Release and x64) ? Alternatively, you can use Ninja, which is quite simple to use. And then you can see the internal error.

pip install ninja
set CMAKE_GENERATOR=Ninja

Thanks, I really appreciate your commitment for this! So I’ve run this by Ninja, and it exited pretty fast. The error log is quite long:

-- The CXX compiler identification is GNU 7.2.0
-- The C compiler identification is GNU 7.2.0
-- Check for working CXX compiler: C:/Program Files/Haskell Platform/8.4.3/mingw/bin/c++.exe
-- Check for working CXX compiler: C:/Program Files/Haskell Platform/8.4.3/mingw/bin/c++.exe -- broken
CMake Error at C:/Users/MarcinM/AppData/Local/Programs/Python/Python36/Lib/site-packages/cmake/data/share/cmake-3.13/Modules/CMakeTestCXXCompiler.cmake:45 (message):
  The C++ compiler

    "C:/Program Files/Haskell Platform/8.4.3/mingw/bin/c++.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/MarcinM/pytorch/build/CMakeFiles/CMakeTmp

    Run Build Command:"C:/Users/MarcinM/AppData/Local/Programs/Python/Python36/Scripts/ninja.exe" "cmTC_42959"
    [1/2] Building CXX object CMakeFiles/cmTC_42959.dir/testCXXCompiler.cxx.obj
    FAILED: CMakeFiles/cmTC_42959.dir/testCXXCompiler.cxx.obj
    C:\PROGRA~1\HASKEL~1\847A5C~1.3\mingw\bin\C__~1.EXE    /EHa -o CMakeFiles/cmTC_42959.dir/testCXXCompiler.cxx.obj -c testCXXCompiler.cxx
    C__~1.EXE: error: /EHa: No such file or directory
    ninja: build stopped: subcommand failed.




  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:11 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/MarcinM/pytorch/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/MarcinM/pytorch/build/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
  File "setup.py", line 710, in <module>
    build_deps()
  File "setup.py", line 282, in build_deps
    build_dir='build')
  File "C:\Users\MarcinM\pytorch\tools\build_pytorch_libs.py", line 253, in build_caffe2
    my_env)
  File "C:\Users\MarcinM\pytorch\tools\build_pytorch_libs.py", line 233, in run_cmake
    check_call(cmake_args, cwd=build_dir, env=my_env)
  File "C:\Users\MarcinM\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '-GNinja', '-DBUILDING_WITH_TORCH_LIBS=ON', '-DBUILD_BINARY=False', '-DBUILD_CAFFE2_OPS=True', '-DBUILD_PYTHON=True', '-DBUILD_SHARED_LIBS=ON', '-DBUILD_TEST=True', '-DBUILD_TORCH=ON', '-DCAFFE2_STATIC_LINK_CUDA=False', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_CXX_FLAGS=  /EHa', '-DCMAKE_C_FLAGS=  /EHa', '-DCMAKE_EXE_LINKER_FLAGS=', '-DCMAKE_INSTALL_PREFIX=C:\\Users\\MarcinM\\pytorch/torch', '-DCMAKE_PREFIX_PATH=C:\\Users\\MarcinM\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages', '-DCMAKE_SHARED_LINKER_FLAGS=', '-DINSTALL_TEST=True', '-DNCCL_EXTERNAL=False', '-DNUMPY_INCLUDE_DIR=C:/Users/MarcinM/AppData/Local/Programs/Python/Python36/lib/site-packages/numpy/core/include', '-DONNX_ML=False', '-DONNX_NAMESPACE=onnx_torch', '-DPYTHON_EXECUTABLE=C:/Users/MarcinM/AppData/Local/Programs/Python/Python36/python.exe', '-DPYTHON_INCLUDE_DIR=C:/Users/MarcinM/AppData/Local/Programs/Python/Python36/include', '-DPYTHON_LIBRARY=C:/Users/MarcinM/AppData/Local/Programs/Python/Python36/libs/python36.lib', '-DTHD_SO_VERSION=1', '-DTORCH_BUILD_VERSION=1.1.0a0+e5cdd94', '-DUSE_CUDA=True', '-DUSE_DISTRIBUTED=False', '-DUSE_FBGEMM=True', '-DUSE_FFMPEG=False', '-DUSE_LEVELDB=False', '-DUSE_LMDB=False', '-DUSE_MKLDNN=True', '-DUSE_NCCL=False', '-DUSE_NNPACK=True', '-DUSE_NUMPY=True', '-DUSE_OPENCV=False', '-DUSE_QNNPACK=True', '-DUSE_ROCM=False', '-DUSE_SYSTEM_EIGEN_INSTALL=OFF', '-DUSE_SYSTEM_NCCL=False', '-DUSE_TENSORRT=False', '-DMKLDNN_ENABLE_CONCURRENT_EXEC=ON', 'C:\\Users\\MarcinM\\pytorch']' returned non-zero exit status 1.

The folder C:/Users/MarcinM/pytorch/build/CMakeFiles/CMakeTmp is empty if this is any help. Also the c++.exe file is present in C:\Program Files\Haskell Platform\8.4.3\mingw\bin.

Oh, I’m missing these variables.

set CC=cl.exe
set CXX=cl.exe

Ok, so there is a lot of similar errors like this (I’ve also changed polish phrases):

[1624/2499] Building NVCC (Device) object caffe2/CMakeFile...en/src/ATen/native/cuda/caffe2_gpu_generated_Reduce.cu.obj
FAILED: caffe2/CMakeFiles/caffe2_gpu.dir/__/aten/src/ATen/native/cuda/caffe2_gpu_generated_Reduce.cu.obj
cmd.exe /C "cd /D C:\Users\MarcinM\pytorch\build\caffe2\CMakeFiles\caffe2_gpu.dir\__\aten\src\ATen\native\cuda && C:\Users\MarcinM\AppData\Local\Programs\Python\Python36\Lib\site-packages\cmake\data\bin\cmake.exe -E make_directory C:/Users/MarcinM/pytorch/build/caffe2/CMakeFiles/caffe2_gpu.dir/__/aten/src/ATen/native/cuda/. && C:\Users\MarcinM\AppData\Local\Programs\Python\Python36\Lib\site-packages\cmake\data\bin\cmake.exe -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=C:/Users/MarcinM/pytorch/build/caffe2/CMakeFiles/caffe2_gpu.dir/__/aten/src/ATen/native/cuda/./caffe2_gpu_generated_Reduce.cu.obj -D generated_cubin_file:STRING=C:/Users/MarcinM/pytorch/build/caffe2/CMakeFiles/caffe2_gpu.dir/__/aten/src/ATen/native/cuda/./caffe2_gpu_generated_Reduce.cu.obj.cubin.txt -P C:/Users/MarcinM/pytorch/build/caffe2/CMakeFiles/caffe2_gpu.dir/__/aten/src/ATen/native/cuda/caffe2_gpu_generated_Reduce.cu.obj.Release.cmake"
Failed to run %VS140COMNTOOLS%../../VC/bin/amd64/cl.exe (No such file).
CMake Error at caffe2_gpu_generated_Reduce.cu.obj.Release.cmake:219 (message):
  Error generating
  C:/Users/MarcinM/pytorch/build/caffe2/CMakeFiles/caffe2_gpu.dir/__/aten/src/ATen/native/cuda/./caffe2_gpu_generated_Reduce.cu.obj

and one last error is:

[1625/2499] Linking CXX shared module caffe2\python\caffe2_pybind11_state.cp36-win_amd64.pyd
   Creating library lib\caffe2_pybind11_state.lib and object lib\caffe2_pybind11_state.exp
pybind_state.cc.obj : warning LNK4217: locally defined symbol ?PybindAdditionRegistry@python@caffe2@@YAPEAV?$Registry@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$unique_ptr@UPybindAddition@python@caffe2@@U?$default_delete@UPybindAddition@python@caffe2@@@std@@@2@AEAVmodule@pybind11@@@c10@@XZ (class c10::Registry<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::unique_ptr<struct caffe2::python::PybindAddition,struct std::default_delete<struct caffe2::python::PybindAddition> >,class pybind11::module &> * __cdecl caffe2::python::PybindAdditionRegistry(void)) was imported in function "void __cdecl caffe2::python::pybind11_init_caffe2_pybind11_state(class pybind11::module &)" (?pybind11_init_caffe2_pybind11_state@python@caffe2@@YAXAEAVmodule@pybind11@@@Z)
pybind_state_nomni.cc.obj : warning LNK4049: locally defined symbol ?PybindAdditionRegistry@python@caffe2@@YAPEAV?$Registry@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$unique_ptr@UPybindAddition@python@caffe2@@U?$default_delete@UPybindAddition@python@caffe2@@@std@@@2@AEAVmodule@pybind11@@@c10@@XZ (class c10::Registry<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::unique_ptr<struct caffe2::python::PybindAddition,struct std::default_delete<struct caffe2::python::PybindAddition> >,class pybind11::module &> * __cdecl caffe2::python::PybindAdditionRegistry(void)) was imported
pybind_state_int8.cc.obj : warning LNK4217: locally defined symbol ?BlobFetcherRegistry@python@caffe2@@YAPEAV?$Registry@VTypeIdentifier@caffe2@@V?$unique_ptr@VBlobFetcherBase@python@caffe2@@U?$default_delete@VBlobFetcherBase@python@caffe2@@@std@@@std@@$$V@c10@@XZ (class c10::Registry<class caffe2::TypeIdentifier,class std::unique_ptr<class caffe2::python::BlobFetcherBase,struct std::default_delete<class caffe2::python::BlobFetcherBase> > > * __cdecl caffe2::python::BlobFetcherRegistry(void)) zostal zaimportowany w funkcji "void __cdecl caffe2::python::`dynamic initializer for 'g_BlobFetcherRegistry0''(void)" (??__Eg_BlobFetcherRegistry0@python@caffe2@@YAXXZ)
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "setup.py", line 710, in <module>
    build_deps()
  File "setup.py", line 282, in build_deps
    build_dir='build')
  File "C:\Users\MarcinM\pytorch\tools\build_pytorch_libs.py", line 261, in build_caffe2
    cwd=build_dir, env=my_env)
  File "C:\Users\MarcinM\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '11']' returned non-zero exit status 1.

About Failed to run %VS140COMNTOOLS%../../VC/bin/amd64/cl.exe (No such file)., indeed there is no such path as C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\bin.
Maybe the path should be C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64\cl.exe as implied in caffe2 old repo discussion?

Edit: I’ve changed the path to but with no luck:

Failed to run %VS140COMNTOOLS%../../VC/Tools/MSVC/14.11.25503/bin/HostX64/x64/cl.exe (No such file).

Which is quite weird because the file cl.exe is definitely there.

please try
set CUDAHOSTCXX=

1 Like

Yes! That worked! Everything went well with it. Pytorch was installed, and is working with cuda. Thank you so much peterjc123!

For future readers, to sum up:

  1. I reinstalled drivers for CUDA, reinstalled CUDA with VS extensions and Nsight Compute (actually with everything checked), reinstaled CUDnn
  2. went with
pip install ninja
set CMAKE_GENERATOR=Ninja
set CC=cl.exe
set CXX=cl.exe
set CUDAHOSTCXX=
set DISTUTILS_USE_SDK=1
for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version [15^,16^) -products * -latest -property installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=14.11
python setup.py build --cmake
python setup.py install
3 Likes

Hello, I’m trying to build PyTorch from source on Windows, since my video card has Compute Capability 3.0. I have installed all the prerequisites and I have tried the procedure outlined here, but it failed. I came across this thread and attempted the same steps but I’m still unable to install PyTorch. Here is the error:

Microsoft Windows [versão 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Todos os direitos reservados.

C:\Users\César>cd ..

C:\Users> cd ..

C:\>cd pytorch

C:\pytorch>set CMAKE_GENERATOR=Ninja

C:\pytorch>set CC=cl.exe

C:\pytorch>set CXX=cl.exe

C:\pytorch>set CUDAHOSTCXX=

C:\pytorch>set DISTUTILS_USE_SDK=1

C:\pytorch>for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Vis
ual Studio\Installer\vswhere.exe" -version [15^,16^) -products * -latest -proper
ty installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_
ver=14.11

C:\pytorch>call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\
VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=14.11
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\pytorch>python setup.py build --cmake
Building wheel torch-1.6.0a0+5e0a24f
-- Building version 1.6.0a0+5e0a24f
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -
DCMAKE_GENERATOR=Ninja -DCMAKE_INSTALL_PREFIX=C:\pytorch\torch -DCMAKE_PREFIX_PA
TH=C:\ProgramData\Miniconda3\Lib\site-packages -DJAVA_HOME=C:\Program Files\Java
\jdk1.8.0_181 -DNUMPY_INCLUDE_DIR=C:\ProgramData\Miniconda3\lib\site-packages\nu
mpy\core\include -DPYTHON_EXECUTABLE=C:\ProgramData\Miniconda3\python.exe -DPYTH
ON_INCLUDE_DIR=C:\ProgramData\Miniconda3\include -DPYTHON_LIBRARY=C:\ProgramData
\Miniconda3/libs/python37.lib -DTORCH_BUILD_VERSION=1.6.0a0+5e0a24f -DUSE_NUMPY=
True C:\pytorch
-- The CXX compiler identification is MSVC 19.11.25548.2
-- The C compiler identification is MSVC 19.11.25548.2
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o/2017/BuildTools/VC/Tools/MSVC/14.11.25503/bin/HostX64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o/2017/BuildTools/VC/Tools/MSVC/14.11.25503/bin/HostX64/x64/cl.exe - broken
CMake Error at C:/ProgramData/Miniconda3/Library/share/cmake-3.17/Modules/CMakeT
estCXXCompiler.cmake:53 (message):
  The C++ compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSV
C/14.11.25503/bin/HostX64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/pytorch/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/ProgramData/Miniconda3/Library/bin/ninja.exe cmTC_f0
8a4 && [1/2] Building CXX object CMakeFiles\cmTC_f08a4.dir\testCXXCompiler.cxx.o
bj
    FAILED: CMakeFiles/cmTC_f08a4.dir/testCXXCompiler.cxx.obj
    C:\PROGRA~2\MIB055~1\2017\BUILDT~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\
cl.exe  /nologo /TP   "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\
include"  /DWIN32 /D_WINDOWS /GR /EHsc  /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /F
oCMakeFiles\cmTC_f08a4.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_f08a4.dir\
 /FS -c testCXXCompiler.cxx
    include
    c1xx: fatal error C1083: Não é possível abrir arquivo fonte: 'C:\Program Fil
es\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include': No such file or directory
    Gerando Código...
    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:23 (project)


-- Configuring incomplete, errors occurred!
See also "C:/pytorch/build/CMakeFiles/CMakeOutput.log".
See also "C:/pytorch/build/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
  File "setup.py", line 740, in <module>
    build_deps()
  File "setup.py", line 323, in build_deps
    cmake=cmake)
  File "C:\pytorch\tools\build_pytorch_libs.py", line 59, in build_caffe2
    rerun_cmake)
  File "C:\pytorch\tools\setup_helpers\cmake.py", line 324, in generate
    self.run(args, env=my_env)
  File "C:\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "C:\ProgramData\Miniconda3\lib\subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '-GNinja', '-DBUILD_PYTHON=Tru
e', '-DBUILD_TEST=True', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_GENERATOR=Ninja'
, '-DCMAKE_INSTALL_PREFIX=C:\\pytorch\\torch', '-DCMAKE_PREFIX_PATH=C:\\ProgramD
ata\\Miniconda3\\Lib\\site-packages', '-DJAVA_HOME=C:\\Program Files\\Java\\jdk1
.8.0_181', '-DNUMPY_INCLUDE_DIR=C:\\ProgramData\\Miniconda3\\lib\\site-packages\
\numpy\\core\\include', '-DPYTHON_EXECUTABLE=C:\\ProgramData\\Miniconda3\\python
.exe', '-DPYTHON_INCLUDE_DIR=C:\\ProgramData\\Miniconda3\\include', '-DPYTHON_LI
BRARY=C:\\ProgramData\\Miniconda3/libs/python37.lib', '-DTORCH_BUILD_VERSION=1.6
.0a0+5e0a24f', '-DUSE_NUMPY=True', 'C:\\pytorch']' returned non-zero exit status
 1.

C:\pytorch>

I am pretty sure everything is correctly installed. The folder “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include” exists. I have tried reinstalling the CUDA drivers with all the extensions twice and it still does not work.

Could you please show me the output of the following command in CMD: set?

It is probably because some environmental variables are not correctly set, like INCLUDE or LIB.

Here it is:

Microsoft Windows [versão 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Todos os direitos reservados.

C:\Users\César>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\César\AppData\Roaming
asl.log=Destination=file
CFLAGS="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include"
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=CÉSAR-PC
ComSpec=C:\Windows\system32\cmd.exe
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1
CUDA_PATH_V10_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1
CUDA_PATH_V10_2=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\César
INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
LDFLAGS=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\lib\x64
LIBRARY_PATH=C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um
LOCALAPPDATA=C:\Users\César\AppData\Local
LOGONSERVER=\\CÉSAR-PC
MAYA_SCRIPT_PATH=%VPROJECT%\..\sdktools\maya\scripts
NUMBER_OF_PROCESSORS=6
NVCC=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\bin\nvcc.exe
NVCUDASAMPLES10_1_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1
NVCUDASAMPLES10_2_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.2
NVCUDASAMPLES9_2_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.2
NVCUDASAMPLES_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1
NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\
OS=Windows_NT
Path=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;C:\Program Fil
es\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;;C:\Program Files\NVIDIA GPU
Computing Toolkit\CUDA\v10.2\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\C
UDA\v10.2\libnvvp;C:\ProgramData\Miniconda3;C:\ProgramData\Miniconda3\Library\mi
ngw-w64\bin;C:\ProgramData\Miniconda3\Library\usr\bin;C:\ProgramData\Miniconda3\
Library\bin;C:\ProgramData\Miniconda3\Scripts;C:\Program Files (x86)\Common File
s\Oracle\Java\javapath;H:\Rockwell\RSCommon;C:\Program Files\NVIDIA GPU Computin
g Toolkit\CUDA\v9.2\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\
libnvvp;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program F
iles (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Win
dows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Pro
gram Files (x86)\Windows Live\Shared;C:\Program Files\Java\jdk1.8.0_181\bin;C:\P
rogram Files\NVIDIA Corporation\NVIDIA NvDLISR;H:\MATLAB\runtime\win64;H:\MATLAB
\bin;H:\MATLAB\polyspace\bin;C:\Program Files\Calibre2\;C:\freeglut\bin;C:\freeg
lut\bin\x64;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\lib\x64;C:\P
rogram Files (x86)\NVIDIA Corporation\PhysX\Common;C:\FFmpeg\bin;C:\Program File
s (x86)\sox-14-4-2;H:\MikTex\miktex\bin\x64\;C:\Program Files\nodejs\;C:\Users\C
ésar\AppData\Local\GitHubDesktop\bin;C:\Program Files\Git\cmd;C:\Program Files\L
LVM\bin;C:\Program Files (x86)\Tesseract-OCR;C:\Program Files\dotnet\;C:\Program
 Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1;C:\Program Files\NVIDIA Corporati
on\Nsight Compute 2019.1\;C:\Program Files\CMake;C:\Users\César\AppData\Local\Pr
ograms\Python\Python38\Scripts\;C:\Users\César\AppData\Local\Programs\Python\Pyt
hon38\;C:\Python27\;C:\Users\César\AppData\Local\Programs\Python\Python36\Script
s\;C:\Users\César\AppData\Local\Programs\Python\Python36\;C:\Program Files\NVIDI
A GPU Computing Toolkit\CUDA\v9.0\bin;C:\Program Files (x86)\sox-14-4-2;%VPROJEC
T%\..\bin;C:\freeglut\bin\x64;C:\Users\César\AppData\Local\GitHubDesktop\bin;H:\
PyCharm\PyCharm Community Edition 2019.3\bin;C:\Users\César\AppData\Roaming\npm;
C:\Users\César\AppData\Local\Programs\Microsoft VS Code\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=AMD64 Family 21 Model 2 Stepping 0, AuthenticAMD
PROCESSOR_LEVEL=21
PROCESSOR_REVISION=0200
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
PyCharm Community Edition=H:\PyCharm\PyCharm Community Edition 2019.3\bin;
SESSIONNAME=Console
sourcesdk=H:\SteamLibrary\steamapps\common\SourceSDK
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\CSAR~1\AppData\Local\Temp
TMP=C:\Users\CSAR~1\AppData\Local\Temp
USERDOMAIN=César-PC
USERNAME=César
USERPROFILE=C:\Users\César
VBOX_MSI_INSTALL_PATH=D:\Arquivos de Programas\Oracle\VirtualBox\
windir=C:\Windows
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
XSI_PLUGINS=%VPROJECT%\..\sdktools\xsi\5.1\valvesource
XSI_VERSION=5.1

C:\Users\César>

Please clear the value of CFLAGS using set CFLAGS=, remove the cache in the build dir and try again.

Hello, I am having a similar issue and I am not sure how to fix it.

I am trying to build Pytorch from source on Windows 10. I have an old 780m GPU so I use CUDA 10.1.

What I have been doing is in this order:

  • Installed Visual Studio 2019 with the Desktop C++ toolset
  • Installed CUDA 10.1 with visual studio integration (everything checked under CUDA basically) => success
  • Added Cudnn 10.1 to the CUDA folder as explained in the nvidia documentation
  • conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
  • git clone --recursive https://github.com/pytorch/pytorch
  • cd pytorch
  • python setup.py install

And everything seems to go smoothly, except that a pop-up saying that the C++ compiler stopped working appears during compilation. If I don’t touch this pop-up the program keeps compiling for several hours until it hangs at some point, and when I select “close the program” in the pop-up the following error appears in conda prompt:

C:\Users\Yann\Desktop\git\pytorch\third_party\ideep\mkl-dnn\src\cpu\gemm_convolution_utils.cpp(401) : fatal error C1001: Erreur interne du compilateur.
(fichier du compilateur 'd:\agent\_work\7\s\src\vctools\Compiler\Utc\src\p2\main.c', ligne 195)
 Pour contourner ce problème, essayez de simplifier ou de changer le programme à proximité des emplacements listés ci-dessus.
Si possible, indiquez ici la procédure permettant de reproduire le problème : https://developercommunity.visualstudio.com
Choisissez la commande Support technique du menu ? (Aide) de Visual C++,
 ou ouvrez le fichier d'aide du Support technique pour plus d'informations
  cl!RaiseException()+0x69
  cl!RaiseException()+0x69
  cl!CloseTypeServerPDB()+0x22e6b
  cl!CloseTypeServerPDB()+0xcd30a

ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "setup.py", line 748, in <module>
    build_deps()
  File "setup.py", line 327, in build_deps
    build_caffe2(version=version,
  File "C:\Users\Yann\Desktop\git\pytorch\tools\build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py", line 345, in build
    self.run(build_args, my_env)
  File "C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "C:\Users\Yann\anaconda3\envs\pytorch\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '8']' returned non-zero exit status 1.

Did I do something wrong please? I have also tried installing VS2017 instead of 2019 but then the CUDA integration would fail.

I have tried the script from the author, and it failed with this output:

(pytorch) C:\Users\Yann\Desktop\git\pytorch>python setup.py build --cmake
Building wheel torch-1.7.0a0+ac1f471
– Building version 1.7.0a0+ac1f471
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja -DCMAKE_INSTALL_PREFIX=C:\Users\Yann\Desktop\git\pytorch\torch -DCMAKE_PREFIX_PATH=C:\Users\Yann\anaconda3\envs\pytorch\Lib\site-packages -DNUMPY_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\lib\site-packages\numpy\core\include -DPYTHON_EXECUTABLE=C:\Users\Yann\anaconda3\envs\pytorch\python.exe -DPYTHON_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\include -DPYTHON_LIBRARY=C:\Users\Yann\anaconda3\envs\pytorch/libs/python38.lib -DTORCH_BUILD_VERSION=1.7.0a0+ac1f471 -DUSE_NUMPY=True C:\Users\Yann\Desktop\git\pytorch
CMake Error at C:/Users/Yann/anaconda3/envs/pytorch/Library/share/cmake-3.17/Modules/CMakeDetermineCXXCompiler.cmake:48 (message):
Could not find compiler set in environment variable CXX:

cl.exe.

Call Stack (most recent call first):
CMakeLists.txt:23 (project)

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
– Configuring incomplete, errors occurred!
See also “C:/Users/Yann/Desktop/git/pytorch/build/CMakeFiles/CMakeOutput.log”.
See also “C:/Users/Yann/Desktop/git/pytorch/build/CMakeFiles/CMakeError.log”.
Traceback (most recent call last):
File “setup.py”, line 748, in
build_deps()
File “setup.py”, line 327, in build_deps
build_caffe2(version=version,
File “C:\Users\Yann\Desktop\git\pytorch\tools\build_pytorch_libs.py”, line 54, in build_caffe2
cmake.generate(version,
File “C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py”, line 329, in generate
self.run(args, env=my_env)
File “C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py”, line 141, in run
check_call(command, cwd=self.build_dir, env=env)
File “C:\Users\Yann\anaconda3\envs\pytorch\lib\subprocess.py”, line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘cmake’, ‘-GNinja’, ‘-DBUILD_PYTHON=True’, ‘-DBUILD_TEST=True’, ‘-DCMAKE_BUILD_TYPE=Release’, ‘-DCMAKE_GENERATOR=Ninja’, ‘-DCMAKE_INSTALL_PREFIX=C:\Users\Yann\Desktop\git\pytorch\torch’, ‘-DCMAKE_PREFIX_PATH=C:\Users\Yann\anaconda3\envs\pytorch\Lib\site-packages’, ‘-DNUMPY_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\lib\site-packages\numpy\core\include’, ‘-DPYTHON_EXECUTABLE=C:\Users\Yann\anaconda3\envs\pytorch\python.exe’, ‘-DPYTHON_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\include’, ‘-DPYTHON_LIBRARY=C:\Users\Yann\anaconda3\envs\pytorch/libs/python38.lib’, ‘-DTORCH_BUILD_VERSION=1.7.0a0+ac1f471’, ‘-DUSE_NUMPY=True’, ‘C:\Users\Yann\Desktop\git\pytorch’]’ returned non-zero exit status 1.

Then I tried to set CC and CXX manually to the absolute path of cl.exe, and it failed with the following output:

(pytorch) C:\Users\Yann\Desktop\git\pytorch>python setup.py build --cmake
Building wheel torch-1.7.0a0+ac1f471
– Building version 1.7.0a0+ac1f471
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja -DCMAKE_INSTALL_PREFIX=C:\Users\Yann\Desktop\git\pytorch\torch -DCMAKE_PREFIX_PATH=C:\Users\Yann\anaconda3\envs\pytorch\Lib\site-packages -DNUMPY_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\lib\site-packages\numpy\core\include -DPYTHON_EXECUTABLE=C:\Users\Yann\anaconda3\envs\pytorch\python.exe -DPYTHON_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\include -DPYTHON_LIBRARY=C:\Users\Yann\anaconda3\envs\pytorch/libs/python38.lib -DTORCH_BUILD_VERSION=1.7.0a0+ac1f471 -DUSE_NUMPY=True C:\Users\Yann\Desktop\git\pytorch
– The CXX compiler identification is MSVC 19.27.29111.0
– The C compiler identification is MSVC 19.27.29111.0
– Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
– Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Users/Yann/anaconda3/envs/pytorch/Library/share/cmake-3.17/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler

"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/Users/Yann/Desktop/git/pytorch/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Users/Yann/anaconda3/envs/pytorch/Library/bin/ninja.exe cmTC_0a5a6 && [1/2] Building CXX object CMakeFiles\cmTC_0a5a6.dir\testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_0a5a6.exe
FAILED: cmTC_0a5a6.exe
cmd.exe /C "cd . && C:\Users\Yann\anaconda3\envs\pytorch\Library\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_0a5a6.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests  -- C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\1427~1.291\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_0a5a6.dir\testCXXCompiler.cxx.obj  /out:cmTC_0a5a6.exe /implib:cmTC_0a5a6.lib /pdb:cmTC_0a5a6.pdb /version:0.0  /machine:x64  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
RC Pass 1: command "rc /fo CMakeFiles\cmTC_0a5a6.dir/manifest.res CMakeFiles\cmTC_0a5a6.dir/manifest.rc" failed (exit code 0) with the following output:
Le fichier spécifié est introuvable
ninja: build stopped: subcommand failed.

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:23 (project)

– Configuring incomplete, errors occurred!
See also “C:/Users/Yann/Desktop/git/pytorch/build/CMakeFiles/CMakeOutput.log”.
See also “C:/Users/Yann/Desktop/git/pytorch/build/CMakeFiles/CMakeError.log”.
Traceback (most recent call last):
File “setup.py”, line 748, in
build_deps()
File “setup.py”, line 327, in build_deps
build_caffe2(version=version,
File “C:\Users\Yann\Desktop\git\pytorch\tools\build_pytorch_libs.py”, line 54, in build_caffe2
cmake.generate(version,
File “C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py”, line 329, in generate
self.run(args, env=my_env)
File “C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py”, line 141, in run
check_call(command, cwd=self.build_dir, env=env)
File “C:\Users\Yann\anaconda3\envs\pytorch\lib\subprocess.py”, line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘cmake’, ‘-GNinja’, ‘-DBUILD_PYTHON=True’, ‘-DBUILD_TEST=True’, ‘-DCMAKE_BUILD_TYPE=Release’, ‘-DCMAKE_GENERATOR=Ninja’, ‘-DCMAKE_INSTALL_PREFIX=C:\Users\Yann\Desktop\git\pytorch\torch’, ‘-DCMAKE_PREFIX_PATH=C:\Users\Yann\anaconda3\envs\pytorch\Lib\site-packages’, ‘-DNUMPY_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\lib\site-packages\numpy\core\include’, ‘-DPYTHON_EXECUTABLE=C:\Users\Yann\anaconda3\envs\pytorch\python.exe’, ‘-DPYTHON_INCLUDE_DIR=C:\Users\Yann\anaconda3\envs\pytorch\include’, ‘-DPYTHON_LIBRARY=C:\Users\Yann\anaconda3\envs\pytorch/libs/python38.lib’, ‘-DTORCH_BUILD_VERSION=1.7.0a0+ac1f471’, ‘-DUSE_NUMPY=True’, ‘C:\Users\Yann\Desktop\git\pytorch’]’ returned non-zero exit status 1.

EDIT:

Now I have tried to uninstall everything, install VS2017 with both the 14.11 and the 14.13 toolsets, installed CUDA 10.0 (successfully) and the corresponding cudnn, and have been retrying the script from the author. This time it starts compiling for a while, but at some point ninja fails with this kind of output:

Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/internal/custom/gmock-generated-actions.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/gmock-generated-function-mockers.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/gmock-spec-builders.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/gmock-matchers.h
Remarque : inclusion du fichier : C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\math.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/internal/custom/gmock-matchers.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/gmock-generated-matchers.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/gmock-generated-nice-strict.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/gmock-more-actions.h
Remarque : inclusion du fichier : …\cmake…\third_party\googletest\googlemock\include\gmock/gmock-more-matchers.hninja: build stopped: subcommand failed.
Traceback (most recent call last):
File “setup.py”, line 748, in
build_deps()
File “setup.py”, line 327, in build_deps
build_caffe2(version=version,
File “C:\Users\Yann\Desktop\git\pytorch\tools\build_pytorch_libs.py”, line 62, in build_caffe2
cmake.build(my_env)
File “C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py”, line 345, in build
self.run(build_args, my_env)
File “C:\Users\Yann\Desktop\git\pytorch\tools\setup_helpers\cmake.py”, line 141, in run
check_call(command, cwd=self.build_dir, env=env)
File “C:\Users\Yann\anaconda3\lib\subprocess.py”, line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘cmake’, ‘–build’, ‘.’, ‘–target’, ‘install’, ‘–config’, ‘Release’, ‘–’, ‘-j’, ‘8’]’ returned non-zero exit status 1.

Been trying with both -vcvars_ver=14.11 and -vcvars_ver=14.13, I had the same issue in both cases. I don’t know what else to try, help would be appreciated please.